# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
77832 | 2018-09-30T16:58:21 Z | Vardanyan | The Kingdom of JOIOI (JOI17_joioi) | C++14 | 4000 ms | 58312 KB |
#include <bits/stdc++.h> using namespace std; const int N = 2007; int a[N][N]; int n,m; int mns = 1000*1000*1000; bool rot(){ vector<vector<int> > v; for(int i = 1;i<=n;i++){ vector<int> u; for(int j = 1;j<=m;j++) u.push_back(a[i][j]); reverse(u.begin(),u.end()); v.push_back(u); } for(int j = 1;j<=n;j++){ for(int i = 0;i<v[j-1].size();i++){ a[i+1][j] = v[j-1][i]; } } swap(n,m); } bool check(int x){ bool f = false; int ed = m; int mx = 0; int mn = 1000*1000*1000+5; for(int i = 1;i<=n;i++){ for(int j = 1;j<=ed;j++){ if(a[i][j]-mns>x){ ed = j-1; break; } } for(int j = ed+1;j<=m;j++){ mx = max(mx,a[i][j]); mn = min(mn,a[i][j]); } } if(mx-mn<=x) f = true; ///////////////////////// rot(); ed = m; mx = 0; mn = 1000*1000*1000+5; for(int i = 1;i<=n;i++){ for(int j = 1;j<=ed;j++){ if(a[i][j]-mns>x){ ed = j-1; break; } } for(int j = ed+1;j<=m;j++){ mx = max(mx,a[i][j]); mn = min(mn,a[i][j]); } } if(mx-mn<=x) f = true; ///////////////////////// rot(); ed = m; mx = 0; mn = 1000*1000*1000+5; for(int i = 1;i<=n;i++){ for(int j = 1;j<=ed;j++){ if(a[i][j]-mns>x){ ed = j-1; break; } } for(int j = ed+1;j<=m;j++){ mx = max(mx,a[i][j]); mn = min(mn,a[i][j]); } } if(mx-mn<=x) f = true; ///////////////////////// rot(); ed = m; mx = 0; mn = 1000*1000*1000+5; for(int i = 1;i<=n;i++){ for(int j = 1;j<=ed;j++){ if(a[i][j]-mns>x){ ed = j-1; break; } } for(int j = ed+1;j<=m;j++){ mx = max(mx,a[i][j]); mn = min(mn,a[i][j]); } } if(mx-mn<=x) f = true; ///////////////////////// rot(); ///////////////////////// return f; } int main(){ scanf("%d%d",&n,&m); for(int i = 1;i<=n;i++) for(int j = 1;j<=m;j++){ scanf("%d",&a[i][j]); mns = min(mns,a[i][j]); } int l = 0; int r = 1000*1000*1000; int ans = r; while(l<=r){ int mid = (l+r)/2; if(check(mid)){ ans = mid; r = mid-1; } else l = mid+1; } cout<<ans<<endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 632 KB | Output is correct |
2 | Correct | 3 ms | 632 KB | Output is correct |
3 | Correct | 2 ms | 632 KB | Output is correct |
4 | Correct | 3 ms | 764 KB | Output is correct |
5 | Correct | 2 ms | 764 KB | Output is correct |
6 | Correct | 3 ms | 764 KB | Output is correct |
7 | Correct | 2 ms | 764 KB | Output is correct |
8 | Correct | 3 ms | 764 KB | Output is correct |
9 | Correct | 2 ms | 764 KB | Output is correct |
10 | Correct | 3 ms | 768 KB | Output is correct |
11 | Correct | 3 ms | 768 KB | Output is correct |
12 | Correct | 3 ms | 836 KB | Output is correct |
13 | Correct | 3 ms | 836 KB | Output is correct |
14 | Correct | 3 ms | 848 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 632 KB | Output is correct |
2 | Correct | 3 ms | 632 KB | Output is correct |
3 | Correct | 2 ms | 632 KB | Output is correct |
4 | Correct | 3 ms | 764 KB | Output is correct |
5 | Correct | 2 ms | 764 KB | Output is correct |
6 | Correct | 3 ms | 764 KB | Output is correct |
7 | Correct | 2 ms | 764 KB | Output is correct |
8 | Correct | 3 ms | 764 KB | Output is correct |
9 | Correct | 2 ms | 764 KB | Output is correct |
10 | Correct | 3 ms | 768 KB | Output is correct |
11 | Correct | 3 ms | 768 KB | Output is correct |
12 | Correct | 3 ms | 836 KB | Output is correct |
13 | Correct | 3 ms | 836 KB | Output is correct |
14 | Correct | 3 ms | 848 KB | Output is correct |
15 | Correct | 9 ms | 1624 KB | Output is correct |
16 | Correct | 51 ms | 2096 KB | Output is correct |
17 | Correct | 67 ms | 2396 KB | Output is correct |
18 | Correct | 59 ms | 2680 KB | Output is correct |
19 | Correct | 62 ms | 2956 KB | Output is correct |
20 | Correct | 54 ms | 3196 KB | Output is correct |
21 | Correct | 65 ms | 3580 KB | Output is correct |
22 | Correct | 59 ms | 3976 KB | Output is correct |
23 | Correct | 65 ms | 4356 KB | Output is correct |
24 | Correct | 56 ms | 4676 KB | Output is correct |
25 | Correct | 69 ms | 5084 KB | Output is correct |
26 | Correct | 61 ms | 5576 KB | Output is correct |
27 | Correct | 64 ms | 5976 KB | Output is correct |
28 | Correct | 64 ms | 6352 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 632 KB | Output is correct |
2 | Correct | 3 ms | 632 KB | Output is correct |
3 | Correct | 2 ms | 632 KB | Output is correct |
4 | Correct | 3 ms | 764 KB | Output is correct |
5 | Correct | 2 ms | 764 KB | Output is correct |
6 | Correct | 3 ms | 764 KB | Output is correct |
7 | Correct | 2 ms | 764 KB | Output is correct |
8 | Correct | 3 ms | 764 KB | Output is correct |
9 | Correct | 2 ms | 764 KB | Output is correct |
10 | Correct | 3 ms | 768 KB | Output is correct |
11 | Correct | 3 ms | 768 KB | Output is correct |
12 | Correct | 3 ms | 836 KB | Output is correct |
13 | Correct | 3 ms | 836 KB | Output is correct |
14 | Correct | 3 ms | 848 KB | Output is correct |
15 | Correct | 9 ms | 1624 KB | Output is correct |
16 | Correct | 51 ms | 2096 KB | Output is correct |
17 | Correct | 67 ms | 2396 KB | Output is correct |
18 | Correct | 59 ms | 2680 KB | Output is correct |
19 | Correct | 62 ms | 2956 KB | Output is correct |
20 | Correct | 54 ms | 3196 KB | Output is correct |
21 | Correct | 65 ms | 3580 KB | Output is correct |
22 | Correct | 59 ms | 3976 KB | Output is correct |
23 | Correct | 65 ms | 4356 KB | Output is correct |
24 | Correct | 56 ms | 4676 KB | Output is correct |
25 | Correct | 69 ms | 5084 KB | Output is correct |
26 | Correct | 61 ms | 5576 KB | Output is correct |
27 | Correct | 64 ms | 5976 KB | Output is correct |
28 | Correct | 64 ms | 6352 KB | Output is correct |
29 | Execution timed out | 4016 ms | 58312 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |