1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| #include<bits/stdc++.h> #define ll long long #define ull unsigned long long #define maxn 1000005 #define put() putchar('\n') #define Tp template<typename Ty> #define Ts template<typename Ty,typename... Ar> using namespace std; inline void read(int &x){ int f=1;x=0;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();} x*=f; } namespace Debug{ Tp void _debug(char* f,Ty t){cerr<<f<<'='<<t<<endl;} Ts void _debug(char* f,Ty x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);} Tp ostream& operator<<(ostream& os,vector<Ty>& V){os<<"[";for(auto& vv:V) os<<vv<<",";os<<"]";return os;} #define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__) }using namespace Debug; int t[maxn],K,Max; inline int calc(int n,int m,int tmpx,int tmpy,int i) { int sum=0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6,tmp7,tmp8; if (tmpx>i) tmp1=tmp2=tmpy,sum--; else tmp1=tmpy-(i-tmpx+1),tmp2=tmpy+(i-tmpx+1); if (tmpx+i<=n) tmp3=tmp4=tmpy,sum--; else tmp3=tmpy-(i-n+tmpx),tmp4=tmpy+(i-n+tmpx); if (tmpy>i) tmp5=tmp6=tmpy-i,sum--; else tmp5=tmp6=1; if (tmpy+i<=m) tmp7=tmp8=tmpy+i,sum--; else tmp7=tmp8=m;
if (tmp1>=tmp5) sum+=tmp1-tmp5+1; if (tmp2<=tmp7) sum+=tmp7-tmp2+1; if (tmp3>=tmp6) sum+=tmp3-tmp6+1; if (tmp4<=tmp8) sum+=tmp8-tmp4+1; return sum; } inline void solve(int n,int m) { if (Max>n+m-2) return ; int i,j,tmpx=0,tmpy=0,flag=0; if (t[Max]==4) { if (n%2==1&&m%2==1) { tmpx=n/2+1,tmpy=m/2+1; for (i=1;i<Max;i++) if (calc(n,m,tmpx,tmpy,i)!=t[i]) return ; printf("%d %d\n%d %d",n,m,tmpx,tmpy);exit(0); } } else if (t[Max]==3||t[Max]>4) return; else if (t[Max]==2) { if (n%2==0&&m%2==0) return ; if (m%2==1) { tmpy=(m+1)/2;tmpx=n-(Max-tmpy+1);flag=0; for (i=1;i<Max;i++) if (calc(n,m,tmpx,tmpy,i)!=t[i]) {flag=1;break;} if (!flag) {printf("%d %d\n%d %d",n,m,tmpx,tmpy);exit(0) ;} } if (n%2==1) { tmpx=(n+1)/2,tmpy=m-(Max-tmpx+1);flag=0; for (i=1;i<Max;i++) if (calc(n,m,tmpx,tmpy,i)!=t[i]) {flag=1;break;} if (!flag) {printf("%d %d\n%d %d",n,m,tmpx,tmpy);exit(0) ;} } } else if (t[Max]==1) { for (j=n-Max;j<=(n+1)/2;j++) { tmpx=j,tmpy=m+n-Max-j;flag=0; for (i=1;i<=Max;i++) if (calc(n,m,tmpx,tmpy,i)!=t[i]) {flag=1;break;} if (!flag) {printf("%d %d\n%d %d",n,m,tmpx,tmpy);exit(0) ;} } } } signed main(void){ int i,j,x; read(K); for (i=1;i<=K;i++) { read(x); if (x>K-1) return puts("-1"),0; t[x]++;Max=max(Max,x); } for (i=1;i*i<=K;i++) if (K%i==0) { solve(i,K/i); } puts("-1"); return 0; }
|