답안 #887484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887484 2023-12-14T15:36:47 Z hafo The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1166 ms 51796 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define Size(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;

template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}

const int MOD = 1e9 + 7;
const int LOG = 21;
const int maxn = 2e3 + 7;
const ll oo = 1e9 + 69;

int n, m, a[maxn][maxn], mx, mn, b[maxn][maxn];

bool ok(int d) { 
    int last = 0;
    for(int i = 1; i <= n; i++) {
        int r = m;
        for(int j = m; j >= 1; j--) {
            if(a[i][j] >= mx - d) r--;
            else break;
        }
        maxi(last, r);
        for(int j = 1; j <= last; j++) {
            if(a[i][j] > mn + d) return 0;
        }

    }
    return 1;
}

void flip() {
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            b[j][n - i + 1] = a[i][j];
        }
    }

    swap(n, m);
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) a[i][j] = b[i][j];
    }
}

bool check(int d) {
    int ans = 0;
    for(int i = 0; i < 4; i++) {
        if(ok(d)) return 1;
        flip();
    }
    return 0;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //freopen(TASK".inp", "r", stdin);
    //freopen(TASK".out", "w", stdout);

    cin>>n>>m;
    mx = 0;
    mn = oo;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin>>a[i][j];
            maxi(mx, a[i][j]);
            mini(mn, a[i][j]);
        }
    }
        
    int l = 0, r = mx - mn, mid, res;
    while(l <= r) {
        mid = l + r >> 1;
        if(check(mid)) {
            res = mid;
            r = mid - 1;
        } else l = mid + 1;
    }    
    cout<<res;
    return 0;
}

Compilation message

joioi.cpp: In function 'bool check(int)':
joioi.cpp:55:9: warning: unused variable 'ans' [-Wunused-variable]
   55 |     int ans = 0;
      |         ^~~
joioi.cpp: In function 'int main()':
joioi.cpp:83:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |         mid = l + r >> 1;
      |               ~~^~~
joioi.cpp:89:11: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   89 |     cout<<res;
      |           ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2512 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2512 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 5 ms 6748 KB Output is correct
18 Correct 5 ms 6996 KB Output is correct
19 Correct 5 ms 6748 KB Output is correct
20 Correct 7 ms 6748 KB Output is correct
21 Correct 9 ms 7004 KB Output is correct
22 Correct 6 ms 6976 KB Output is correct
23 Correct 6 ms 7004 KB Output is correct
24 Correct 6 ms 7004 KB Output is correct
25 Correct 6 ms 6976 KB Output is correct
26 Correct 6 ms 7000 KB Output is correct
27 Correct 7 ms 7004 KB Output is correct
28 Correct 7 ms 7004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2512 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 5 ms 6748 KB Output is correct
18 Correct 5 ms 6996 KB Output is correct
19 Correct 5 ms 6748 KB Output is correct
20 Correct 7 ms 6748 KB Output is correct
21 Correct 9 ms 7004 KB Output is correct
22 Correct 6 ms 6976 KB Output is correct
23 Correct 6 ms 7004 KB Output is correct
24 Correct 6 ms 7004 KB Output is correct
25 Correct 6 ms 6976 KB Output is correct
26 Correct 6 ms 7000 KB Output is correct
27 Correct 7 ms 7004 KB Output is correct
28 Correct 7 ms 7004 KB Output is correct
29 Correct 775 ms 43088 KB Output is correct
30 Correct 654 ms 42840 KB Output is correct
31 Correct 677 ms 43864 KB Output is correct
32 Correct 884 ms 43688 KB Output is correct
33 Correct 731 ms 42072 KB Output is correct
34 Correct 755 ms 43856 KB Output is correct
35 Correct 1166 ms 51796 KB Output is correct
36 Correct 919 ms 48980 KB Output is correct
37 Correct 1043 ms 51624 KB Output is correct