답안 #1000158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1000158 2024-06-16T18:19:26 Z mispertion The Kingdom of JOIOI (JOI17_joioi) C++17
60 / 100
4000 ms 117584 KB
#include<bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;

#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"

const ld PI = 3.1415926535;
const int N = 5000+10;
const int M = 7e6 + 1;
int mod = 998244353;
const int infi = INT_MAX;
const ll infl = LLONG_MAX;
const int P = 2;

int mult(int a, int b) {
    return a * 1LL * b % mod;
}

int sum(int a, int b) { 
    if (a + b < 0)
        return a + b + mod;
    if (a + b >= mod)
        return a + b - mod;
    return a + b;
}

ll binpow(ll a, ll n) {
    if (n == 0)
        return 1;
    if (n % 2 == 1) {
        return binpow(a, n - 1) * a % mod;
    } else {
        ll b = binpow(a, n / 2);
        return b * b % mod;
    }
}

int H, W;
vector<vector<int>> mat = {};

void rotate(){
    vector<vector<int>> nm(sz(mat[0]), vector<int>(sz(mat)));
    for(int i = 0; i < sz(mat); i++){
        for(int j = 0; j < sz(mat[i]); j++){
            nm[sz(mat[i]) - j - 1][i] = mat[i][j];
        }
    }
    mat = nm;
}

bool check(int mxd){
    int ndmn = infi;
    for(int i = 0; i < sz(mat); i++){
        for(int j = 0; j < sz(mat[i]); j++){
            ndmn = min(ndmn, mat[i][j]);
        }
    }
    int mx = mxd + ndmn;
    int cmx = sz(mat[0]) - 1;
    int dmn = infi, dmx = -infi;
    for(int i = 0; i < sz(mat); i++){
        int ha = 0;
        for(; ha <= cmx; ha++){
            if(mat[i][ha] > mx)
                break;
        }
        cmx = ha - 1;
        //cout << ha << '\n';
        for(int j = ha; j < sz(mat[i]); j++){
            dmn = min(dmn, mat[i][j]);
            dmx = max(dmx, mat[i][j]);
        }
    }
    //cout << '\n';
    return (dmx - dmn <= mxd);
}

void solve(){
    cin >> H >> W;
    mat.assign(H, vector<int>(W, 0));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++)
            cin >> mat[i][j];
    }
    /*cout << '\n';
    for(int k = 0; k < 4; k++){
        for(int i = 0; i < sz(mat); i++)
            for(int j = 0; j < sz(mat[i]); j++)
                cout << mat[i][j] << " \n"[sz(mat[i]) - 1 == j];
        rotate();
        cout << '\n';
    }*/
    int lo = -1, hi = 1e9;
    while(lo + 1 < hi){
        int m = (lo + hi) / 2;
        bool ok = false;
        for(int i = 0; i < 4; i++){
            if(check(m))
                ok = true;
            rotate();
        }
        if(ok)
            hi = m;
        else
            lo = m;
    }
    cout << hi << '\n';
}

signed main() {
    mispertion;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 464 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 464 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 13 ms 1116 KB Output is correct
17 Correct 21 ms 1368 KB Output is correct
18 Correct 15 ms 1116 KB Output is correct
19 Correct 22 ms 1376 KB Output is correct
20 Correct 14 ms 1372 KB Output is correct
21 Correct 22 ms 1488 KB Output is correct
22 Correct 16 ms 1664 KB Output is correct
23 Correct 24 ms 1500 KB Output is correct
24 Correct 15 ms 1628 KB Output is correct
25 Correct 22 ms 1484 KB Output is correct
26 Correct 26 ms 1488 KB Output is correct
27 Correct 22 ms 1484 KB Output is correct
28 Correct 22 ms 1488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 464 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 13 ms 1116 KB Output is correct
17 Correct 21 ms 1368 KB Output is correct
18 Correct 15 ms 1116 KB Output is correct
19 Correct 22 ms 1376 KB Output is correct
20 Correct 14 ms 1372 KB Output is correct
21 Correct 22 ms 1488 KB Output is correct
22 Correct 16 ms 1664 KB Output is correct
23 Correct 24 ms 1500 KB Output is correct
24 Correct 15 ms 1628 KB Output is correct
25 Correct 22 ms 1484 KB Output is correct
26 Correct 26 ms 1488 KB Output is correct
27 Correct 22 ms 1484 KB Output is correct
28 Correct 22 ms 1488 KB Output is correct
29 Correct 2684 ms 111952 KB Output is correct
30 Correct 2658 ms 82260 KB Output is correct
31 Correct 2781 ms 117584 KB Output is correct
32 Execution timed out 4006 ms 86580 KB Time limit exceeded
33 Halted 0 ms 0 KB -