답안 #703919

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703919 2023-02-28T21:24:33 Z stevancv The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
529 ms 54996 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const int inf = 2e9;
const int mod = 1e9 + 7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    int mn = inf; int mx = 0;
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            smin(mn, a[i][j]);
            smax(mx, a[i][j]);
        }
    }
    auto Can = [&] (int x) {
        vector<int> v(n);
        int gde = m;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < gde; j++) {
                if (mn + x < a[i][j]) {
                    gde = j;
                    break;
                }
            }
            v[i] = gde;
        }
        for (int i = 0; i < n; i++) {
            for (int j = v[i]; j < m; j++) {
                if (a[i][j] + x < mx) return 0;
            }
        }
        return 1;
    };
    auto Solve = [&] () {
        int l = 0, r = mx - mn, ans = r;
        while (l <= r) {
            int mid = l + r >> 1;
            if (Can(mid)) {
                ans = mid;
                r = mid - 1;
            }
            else l = mid + 1;
        }
        return ans;
    };
    int ans = Solve();
    reverse(a.begin(), a.end());
    smin(ans, Solve());
    for (int i = 0; i < n; i++) reverse(a[i].begin(), a[i].end());
    smin(ans, Solve());
    reverse(a.begin(), a.end());
    smin(ans, Solve());
    cout << ans << en;
    return 0;
}

Compilation message

joioi.cpp: In lambda function:
joioi.cpp:49:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |             int mid = l + r >> 1;
      |                       ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 4 ms 740 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 4 ms 724 KB Output is correct
20 Correct 5 ms 596 KB Output is correct
21 Correct 6 ms 852 KB Output is correct
22 Correct 8 ms 852 KB Output is correct
23 Correct 8 ms 852 KB Output is correct
24 Correct 5 ms 724 KB Output is correct
25 Correct 7 ms 852 KB Output is correct
26 Correct 9 ms 852 KB Output is correct
27 Correct 7 ms 848 KB Output is correct
28 Correct 6 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 4 ms 740 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 4 ms 724 KB Output is correct
20 Correct 5 ms 596 KB Output is correct
21 Correct 6 ms 852 KB Output is correct
22 Correct 8 ms 852 KB Output is correct
23 Correct 8 ms 852 KB Output is correct
24 Correct 5 ms 724 KB Output is correct
25 Correct 7 ms 852 KB Output is correct
26 Correct 9 ms 852 KB Output is correct
27 Correct 7 ms 848 KB Output is correct
28 Correct 6 ms 852 KB Output is correct
29 Correct 308 ms 37304 KB Output is correct
30 Correct 306 ms 36416 KB Output is correct
31 Correct 333 ms 39176 KB Output is correct
32 Correct 303 ms 39108 KB Output is correct
33 Correct 269 ms 34032 KB Output is correct
34 Correct 325 ms 39216 KB Output is correct
35 Correct 496 ms 54804 KB Output is correct
36 Correct 454 ms 47956 KB Output is correct
37 Correct 529 ms 54996 KB Output is correct