답안 #1096060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096060 2024-10-03T16:31:16 Z thangdz2k7 The Kingdom of JOIOI (JOI17_joioi) C++17
0 / 100
1 ms 504 KB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;

const int N = 2e3 + 5;
const int mod = 1e9 + 7;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

int n, m, a[N][N], mn = mod, mx = 0, b[N][N];

bool check(int val){
    for (int i = 0; i < n; ++ i){
        for (int j = 0; j < m; ++ j){
            b[i][j] = 0;
            if (a[i][j] <= mn + val) b[i][j] |= 1;
            if (a[i][j] >= mx - val) b[i][j] |= 2;
        }
    }

    for (int t : {1, 2}){
        int cur = m - 1; bool ck = true;
        for (int i = 0; i < n; ++ i){
            int fir = m, las = -1;
            for (int j = 0; j < m; ++ j){
                if (b[i][j] == t) las = j;
                if (b[i][j] == (t ^ 3) && fir == m) fir = j;
            }
            minl(cur, fir - 1);
            if (cur < las){
                ck = false;
                break;
            }
        }
        if (ck) return true;

        ck = true; cur = m - 1;
        for (int i = n - 1; i >= 0; -- i){
            int fir = m, las = -1;
            for (int j = 0; j < m; ++ j){
                if (b[i][j] == t) las = j;
                if (b[i][j] == (t ^ 3) && fir == m) fir = j;
            }
            minl(cur, fir - 1);
            if (cur < las){
                ck = false;
                break;
            }
        }
        if (ck) return true;
    }

    return false;
}

void solve(){
    cin >> n >> m;
    for (int i = 0; i < n; ++ i){
        for (int j = 0; j < m; ++ j){
            cin >> a[i][j];
            maxl(mx, a[i][j]); minl(mn, a[i][j]);
        }
    }
    int lo = (mx - mn) >> 1;
    int hi = mx - mn, ans = hi;
    while (lo <= hi){
        int mid = lo + hi >> 1;
        if (check(mid)) ans = mid, hi = mid - 1;
        else lo = mid + 1;
    }
    cout << ans;
}

int main(){
    if (fopen("pqh.inp", "r")){
        freopen("pqh.inp", "r", stdin);
        freopen("pqh.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}

Compilation message

joioi.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
joioi.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
joioi.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
joioi.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
joioi.cpp: In function 'void solve()':
joioi.cpp:78:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   78 |         int mid = lo + hi >> 1;
      |                   ~~~^~~~
joioi.cpp: In function 'int main()':
joioi.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen("pqh.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
joioi.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen("pqh.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -