# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321662 | 2020-11-13T02:07:21 Z | daniel920712 | The Kingdom of JOIOI (JOI17_joioi) | C++14 | 4000 ms | 100724 KB |
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <algorithm> #include <vector> #include <queue> #include <map> using namespace std; int all[2005][2005]; int l1[2005],r1[2005]; int l2[2005],r2[2005]; map < int , vector < pair < int , int > > > where; int main() { int small=2e9,big=0,l,r,N,M,ok,x,y,a,b,c,d,i,j,k; scanf("%d %d",&N,&M); for(i=0;i<N;i++) { for(j=0;j<M;j++) { scanf("%d",&all[i][j]); where[all[i][j]].push_back(make_pair(i,j)); small=min(small,all[i][j]); big=max(big,all[i][j]); } } l=0; r=(big-small+1); while((r-l)>1) { ok=1; for(auto i:where) { if(i.first>small+(r+l)/2) if(big-i.first>(r+l)/2) ok=0; if(i.first<big-(r+l)/2) if(i.first-small>(r+l)/2) ok=0; } if(ok==0) { l=(r+l)/2; continue; } for(i=0;i<N;i++) { l1[i]=l2[i]=M; r1[i]=r2[i]=-1; } for(auto i:where) { for(auto j:i.second) { if(i.first>small+(r+l)/2) { l1[j.first]=min(l1[j.first],j.second); r1[j.first]=max(r1[j.first],j.second); } if(i.first<big-(r+l)/2) { l2[j.first]=min(l2[j.first],j.second); r2[j.first]=max(r2[j.first],j.second); } } } a=b=c=d=1; x=M; for(i=0;i<N;i++) { x=min(x,l1[i]); if(x<=r2[i]) a=0; } x=-1; for(i=0;i<N;i++) { x=max(x,r2[i]); if(x>=l1[i]) b=0; } x=M; for(i=0;i<N;i++) { x=min(x,l2[i]); if(x<=r1[i]) c=0; } x=-1; for(i=0;i<N;i++) { x=max(x,r1[i]); if(x>=l2[i]) d=0; } if(a||b||c||d) r=(l+r)/2; else l=(r+l)/2; } ok=1; for(auto i:where) { if(i.first>small+l) if(big-i.first>l) ok=0; if(i.first<big-l) if(i.first-small>l) ok=0; } if(ok==0) { printf("%d\n",r); return 0; } for(i=0;i<N;i++) { l1[i]=l2[i]=M; r1[i]=r2[i]=-1; } for(auto i:where) { for(auto j:i.second) { if(i.first>small+l) { l1[j.first]=min(l1[j.first],j.second); r1[j.first]=max(r1[j.first],j.second); } if(i.first<big-l) { l2[j.first]=min(l2[j.first],j.second); r2[j.first]=max(r2[j.first],j.second); } } } a=b=c=d=1; x=M; for(i=0;i<N;i++) { x=min(x,l1[i]); if(x<=r2[i]) a=0; } x=-1; for(i=0;i<N;i++) { x=max(x,r2[i]); if(x>=l1[i]) b=0; } x=M; for(i=0;i<N;i++) { x=min(x,l2[i]); if(x<=r1[i]) c=0; } x=-1; for(i=0;i<N;i++) { x=max(x,r1[i]); if(x>=l2[i]) d=0; } if(a||b||c||d) printf("%d\n",l); else printf("%d\n",r); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 492 KB | Output is correct |
16 | Correct | 7 ms | 1900 KB | Output is correct |
17 | Correct | 152 ms | 5996 KB | Output is correct |
18 | Correct | 88 ms | 5868 KB | Output is correct |
19 | Correct | 126 ms | 5868 KB | Output is correct |
20 | Correct | 104 ms | 5228 KB | Output is correct |
21 | Correct | 210 ms | 6252 KB | Output is correct |
22 | Correct | 125 ms | 5996 KB | Output is correct |
23 | Correct | 180 ms | 6124 KB | Output is correct |
24 | Correct | 96 ms | 5484 KB | Output is correct |
25 | Correct | 190 ms | 6124 KB | Output is correct |
26 | Correct | 181 ms | 6124 KB | Output is correct |
27 | Correct | 179 ms | 6252 KB | Output is correct |
28 | Correct | 196 ms | 6252 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 492 KB | Output is correct |
16 | Correct | 7 ms | 1900 KB | Output is correct |
17 | Correct | 152 ms | 5996 KB | Output is correct |
18 | Correct | 88 ms | 5868 KB | Output is correct |
19 | Correct | 126 ms | 5868 KB | Output is correct |
20 | Correct | 104 ms | 5228 KB | Output is correct |
21 | Correct | 210 ms | 6252 KB | Output is correct |
22 | Correct | 125 ms | 5996 KB | Output is correct |
23 | Correct | 180 ms | 6124 KB | Output is correct |
24 | Correct | 96 ms | 5484 KB | Output is correct |
25 | Correct | 190 ms | 6124 KB | Output is correct |
26 | Correct | 181 ms | 6124 KB | Output is correct |
27 | Correct | 179 ms | 6252 KB | Output is correct |
28 | Correct | 196 ms | 6252 KB | Output is correct |
29 | Execution timed out | 4083 ms | 100724 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |