# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
480717 | 2021-10-18T00:49:46 Z | Mackerel_Pike | The Kingdom of JOIOI (JOI17_joioi) | C++14 | 628 ms | 54936 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; int n, m, mn, mx; int a[maxn][maxn]; int l[maxn], r[maxn]; inline bool solve(int md){ for(int i = 0; i < n; ++i){ for(r[i] = -1; r[i] + 1 < m && a[i][r[i] + 1] >= mx - md; ++r[i]); for(l[i] = m; l[i] - 1 >= 0 && a[i][l[i] - 1] <= mn + md; --l[i]); --l[i]; if(l[i] > r[i]) return false; } int lst = -1; bool ok = true; for(int i = 0; i < n; ++i){ lst = max(lst, l[i]); ok &= (lst <= r[i]); } if(ok) return true; lst = m; for(int i = 0; i < n; ++i){ lst = min(lst, r[i]); if(lst < l[i]) return false; } return true; } inline bool check(int md){ if(solve(md)) return true; for(int i = 0; i < n; ++i) reverse(a[i], a[i] + m); return solve(md); } int main(){ //freopen("joioi.in", "r", stdin); scanf("%d%d", &n, &m); mx = 0, mn = 0x3f3f3f3f; for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j) scanf("%d", &a[i][j]), mx = max(mx, a[i][j]), mn = min(mn, a[i][j]); int lb = -1, rb = 1e9; for(; lb + 1 < rb; ){ int md = lb + rb >> 1; if(check(md)) rb = md; else lb = md; } printf("%d\n", rb); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 300 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 304 KB | Output is correct |
7 | Correct | 0 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 296 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 0 ms | 332 KB | Output is correct |
12 | Correct | 0 ms | 332 KB | Output is correct |
13 | Correct | 0 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 300 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 304 KB | Output is correct |
7 | Correct | 0 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 296 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 0 ms | 332 KB | Output is correct |
12 | Correct | 0 ms | 332 KB | Output is correct |
13 | Correct | 0 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 6 ms | 1228 KB | Output is correct |
17 | Correct | 7 ms | 1484 KB | Output is correct |
18 | Correct | 7 ms | 1484 KB | Output is correct |
19 | Correct | 6 ms | 1456 KB | Output is correct |
20 | Correct | 5 ms | 1356 KB | Output is correct |
21 | Correct | 9 ms | 1544 KB | Output is correct |
22 | Correct | 7 ms | 1636 KB | Output is correct |
23 | Correct | 7 ms | 1612 KB | Output is correct |
24 | Correct | 6 ms | 1484 KB | Output is correct |
25 | Correct | 7 ms | 1580 KB | Output is correct |
26 | Correct | 8 ms | 1612 KB | Output is correct |
27 | Correct | 10 ms | 1616 KB | Output is correct |
28 | Correct | 10 ms | 1612 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 300 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 304 KB | Output is correct |
7 | Correct | 0 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 296 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 0 ms | 332 KB | Output is correct |
12 | Correct | 0 ms | 332 KB | Output is correct |
13 | Correct | 0 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 6 ms | 1228 KB | Output is correct |
17 | Correct | 7 ms | 1484 KB | Output is correct |
18 | Correct | 7 ms | 1484 KB | Output is correct |
19 | Correct | 6 ms | 1456 KB | Output is correct |
20 | Correct | 5 ms | 1356 KB | Output is correct |
21 | Correct | 9 ms | 1544 KB | Output is correct |
22 | Correct | 7 ms | 1636 KB | Output is correct |
23 | Correct | 7 ms | 1612 KB | Output is correct |
24 | Correct | 6 ms | 1484 KB | Output is correct |
25 | Correct | 7 ms | 1580 KB | Output is correct |
26 | Correct | 8 ms | 1612 KB | Output is correct |
27 | Correct | 10 ms | 1616 KB | Output is correct |
28 | Correct | 10 ms | 1612 KB | Output is correct |
29 | Correct | 504 ms | 37308 KB | Output is correct |
30 | Correct | 485 ms | 37444 KB | Output is correct |
31 | Correct | 588 ms | 39208 KB | Output is correct |
32 | Correct | 523 ms | 38980 KB | Output is correct |
33 | Correct | 455 ms | 34200 KB | Output is correct |
34 | Correct | 523 ms | 39192 KB | Output is correct |
35 | Correct | 628 ms | 54716 KB | Output is correct |
36 | Correct | 546 ms | 49684 KB | Output is correct |
37 | Correct | 594 ms | 54936 KB | Output is correct |