# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335302 | 2020-12-11T21:51:07 Z | ChrisT | The Kingdom of JOIOI (JOI17_joioi) | C++17 | 1134 ms | 55020 KB |
#include <bits/stdc++.h> using namespace std; const int MN = 2e3 + 3; int a[MN][MN],n,m,x,y; bool __check (int mid) { //a <= mid + min int big = mid + a[x][y]; int mn = 1e9, mx = -1e9; auto upd = [&] (int v) {mn = min(mn,v); mx = max(mx,v);}; vector<int> ed(n+1); for (int i = 1; i <= n; i++) { while (ed[i] < m && a[i][ed[i]+1] <= big) ++ed[i]; } for (int i = n-1; i >= 1; i--) { ed[i] = min(ed[i],ed[i+1]); } if (ed[x] < y) return false; for (int i = 1; i <= n; i++) { for (int j = ed[i] + 1; j <= m; j++) { upd(a[i][j]); } } return mx - mn <= mid; } bool _check (int mid) { if (__check(mid)) return true; reverse(a+1,a+1+n); x = n+1-x; bool ok = __check(mid); x = n+1-x; reverse(a+1,a+1+n); return ok; } bool check (int mid) { if (_check(mid)) return true; for (int i = 1; i <= n; i++) reverse(a[i]+1,a[i]+1+m); y = m+1-y; bool ok = _check(mid); y = m+1-y; for (int i = 1; i <= n; i++) reverse(a[i]+1,a[i]+1+m); return ok; } int main() { scanf ("%d %d",&n,&m); x=y=1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf ("%d",&a[i][j]); if (a[i][j] < a[x][y]) {x = i; y = j;} } } int low = 0, high = 2e9, mid, ans = -1; while (low <= high) { mid = (low + high) / 2; if (check(mid)) high = (ans = mid) - 1; else low = mid + 1; } printf ("%d\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 2 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 2 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 2 ms | 364 KB | Output is correct |
10 | Correct | 2 ms | 364 KB | Output is correct |
11 | Correct | 2 ms | 364 KB | Output is correct |
12 | Correct | 2 ms | 364 KB | Output is correct |
13 | Correct | 2 ms | 364 KB | Output is correct |
14 | Correct | 2 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 | 364 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 2 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 2 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 2 ms | 364 KB | Output is correct |
10 | Correct | 2 ms | 364 KB | Output is correct |
11 | Correct | 2 ms | 364 KB | Output is correct |
12 | Correct | 2 ms | 364 KB | Output is correct |
13 | Correct | 2 ms | 364 KB | Output is correct |
14 | Correct | 2 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 9 ms | 2028 KB | Output is correct |
17 | Correct | 18 ms | 2156 KB | Output is correct |
18 | Correct | 24 ms | 2156 KB | Output is correct |
19 | Correct | 22 ms | 2156 KB | Output is correct |
20 | Correct | 21 ms | 1900 KB | Output is correct |
21 | Correct | 39 ms | 2284 KB | Output is correct |
22 | Correct | 32 ms | 2284 KB | Output is correct |
23 | Correct | 39 ms | 2284 KB | Output is correct |
24 | Correct | 28 ms | 2028 KB | Output is correct |
25 | Correct | 37 ms | 2284 KB | Output is correct |
26 | Correct | 26 ms | 2312 KB | Output is correct |
27 | Correct | 33 ms | 2284 KB | Output is correct |
28 | Correct | 31 ms | 2284 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 2 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 2 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 2 ms | 364 KB | Output is correct |
10 | Correct | 2 ms | 364 KB | Output is correct |
11 | Correct | 2 ms | 364 KB | Output is correct |
12 | Correct | 2 ms | 364 KB | Output is correct |
13 | Correct | 2 ms | 364 KB | Output is correct |
14 | Correct | 2 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 9 ms | 2028 KB | Output is correct |
17 | Correct | 18 ms | 2156 KB | Output is correct |
18 | Correct | 24 ms | 2156 KB | Output is correct |
19 | Correct | 22 ms | 2156 KB | Output is correct |
20 | Correct | 21 ms | 1900 KB | Output is correct |
21 | Correct | 39 ms | 2284 KB | Output is correct |
22 | Correct | 32 ms | 2284 KB | Output is correct |
23 | Correct | 39 ms | 2284 KB | Output is correct |
24 | Correct | 28 ms | 2028 KB | Output is correct |
25 | Correct | 37 ms | 2284 KB | Output is correct |
26 | Correct | 26 ms | 2312 KB | Output is correct |
27 | Correct | 33 ms | 2284 KB | Output is correct |
28 | Correct | 31 ms | 2284 KB | Output is correct |
29 | Correct | 785 ms | 37384 KB | Output is correct |
30 | Correct | 765 ms | 37740 KB | Output is correct |
31 | Correct | 691 ms | 39276 KB | Output is correct |
32 | Correct | 796 ms | 39456 KB | Output is correct |
33 | Correct | 689 ms | 34284 KB | Output is correct |
34 | Correct | 809 ms | 39276 KB | Output is correct |
35 | Correct | 954 ms | 54892 KB | Output is correct |
36 | Correct | 1104 ms | 49772 KB | Output is correct |
37 | Correct | 1134 ms | 55020 KB | Output is correct |