Submission #637349

# Submission time Handle Problem Language Result Execution time Memory
637349 2022-09-01T13:06:28 Z dattranxxx The Kingdom of JOIOI (JOI17_joioi) C++11
100 / 100
521 ms 63264 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2000 + 5, inf = 1e9;
int n, m, max_val = -inf, min_val = inf;
void flipRow(vector<vector<int>>& a) {
  for (int i = 0; i < n/2; ++i)
    for (int j = 0; j < m; ++j) swap(a[i][j], a[n-i-1][j]);
}
void flipCol(vector<vector<int>>& a) {
  for (int j = 0; j < m/2; ++j) 
    for (int i = 0; i < n; ++i) swap(a[i][j], a[i][m-j-1]);
}
int top(int mid, vector<vector<int>>& a) {
  for (int i = 0, cur_r = m-1; i < n; ++i) {
     for (int j = cur_r; ~j; --j) if (max_val - a[i][j] > mid) cur_r = j-1;
     for (int j = cur_r+1; j < m; ++j) if (a[i][j] - min_val > mid) return 0;
  }
  return 1;
}
vector<vector<int>> a[4];
int check(int mid) {
  for (int i = 0; i < 4; ++i)
    if (top(mid, a[i])) return 1;
  return 0; 
}
int main() {
	cin.tie(0)->sync_with_stdio(0); cout.tie(0);
  cin >> n >> m; a[0].resize(n, vector<int>(m));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      cin >> a[0][i][j], 
      max_val = max(max_val, a[0][i][j]),
      min_val = min(min_val, a[0][i][j]);
  a[3] = a[2] = a[1] = a[0];
  for (int i = 0; i < 4; ++i) {
    if (i & 1) flipRow(a[i]);
    if (i & 2) flipCol(a[i]);
  }
  int lo = 0, hi = max_val - min_val, mid, ans = -1;
  while (lo <= hi) {
    mid = lo + hi >> 1;
    if (check(mid))
      ans = mid, hi = mid - 1;
    else
      lo = mid + 1;
  }
  cout << ans;
	return 0;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:42:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |     mid = lo + hi >> 1;
      |           ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 316 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 316 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 5 ms 852 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
19 Correct 5 ms 852 KB Output is correct
20 Correct 4 ms 852 KB Output is correct
21 Correct 7 ms 868 KB Output is correct
22 Correct 6 ms 852 KB Output is correct
23 Correct 5 ms 956 KB Output is correct
24 Correct 6 ms 848 KB Output is correct
25 Correct 5 ms 852 KB Output is correct
26 Correct 6 ms 956 KB Output is correct
27 Correct 8 ms 972 KB Output is correct
28 Correct 5 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 316 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 5 ms 852 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
19 Correct 5 ms 852 KB Output is correct
20 Correct 4 ms 852 KB Output is correct
21 Correct 7 ms 868 KB Output is correct
22 Correct 6 ms 852 KB Output is correct
23 Correct 5 ms 956 KB Output is correct
24 Correct 6 ms 848 KB Output is correct
25 Correct 5 ms 852 KB Output is correct
26 Correct 6 ms 956 KB Output is correct
27 Correct 8 ms 972 KB Output is correct
28 Correct 5 ms 852 KB Output is correct
29 Correct 368 ms 60092 KB Output is correct
30 Correct 394 ms 58536 KB Output is correct
31 Correct 390 ms 63176 KB Output is correct
32 Correct 379 ms 63160 KB Output is correct
33 Correct 328 ms 55196 KB Output is correct
34 Correct 397 ms 63144 KB Output is correct
35 Correct 504 ms 63264 KB Output is correct
36 Correct 463 ms 55244 KB Output is correct
37 Correct 521 ms 63232 KB Output is correct