답안 #995090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995090 2024-06-08T12:30:55 Z _callmelucian The Kingdom of JOIOI (JOI17_joioi) C++14
60 / 100
1743 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

vector<int> cmp;

int getID (int targ) {
    return lower_bound(all(cmp), targ) - cmp.begin();
}

const int mn = 4e6 + 6;
int lo[2002][2002], hi[2002][2002];
int calcLo[mn], calcHi[mn];
vector<pii> contain[mn];

bool check (int delta) {
    int pos = -1, curLo = INT_MAX, curHi = INT_MIN;
    for (int k = 0; k < cmp.size(); k++) {
        while (pos + 1 < cmp.size() && cmp[pos + 1] < cmp[k] - delta) {
            pos++;
            for (auto [row, col] : contain[pos]) {
                curLo = min(curLo, lo[row][col]);
                curHi = max(curHi, hi[row][col]);
            }
        }
        int cHi = max(calcHi[k], curHi);
        int cLo = min(calcLo[k], curLo);
        if (cHi == INT_MIN || cHi - cLo <= delta) return 1;
    }
    return 0;
}

int solve (vector<vector<int>> &vec, int n, int m) {
    for (int i = 1; i <= n; i++)
        lo[i][0] = INT_MAX, hi[i][0] = INT_MIN;
    for (int j = 1; j <= m; j++) {
        int loCol = INT_MAX, hiCol = INT_MIN;
        for (int i = n; i >= 1; i--) {
            lo[i][j] = min(lo[i][j - 1], loCol = min(loCol, vec[i][j]));
            hi[i][j] = max(hi[i][j - 1], hiCol = max(hiCol, vec[i][j]));
        }
    }

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            contain[getID(vec[i][j])].push_back(make_pair(i, j));

    int curLo = INT_MAX, curHi = INT_MIN;
    for (int k = cmp.size() - 1; k >= 0; k--) {
        calcLo[k] = curLo, calcHi[k] = curHi;
        for (auto [row, col] : contain[k]) {
            curLo = min(curLo, lo[row][col]);
            curHi = max(curHi, hi[row][col]);
        }
    }

    int ans = 0;
    if (!check(0)) {
        for (int i = 29; i >= 0; i--) {
            int mask = ans | (1 << i);
            if (!check(mask)) ans |= (1 << i);
        }
        ans++;
    }

    for (int k = 0; k < cmp.size(); k++)
        contain[k].clear();
    return ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m; cin >> n >> m;
    vector<vector<int>> vec(n + 1, vector<int>(m + 1));
    vector<vector<int>> rot(m + 1, vector<int>(n + 1));

    //cmp.push_back(0);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> vec[i][j];
            rot[j][n - i + 1] = vec[i][j];
            cmp.push_back(vec[i][j]);
        }
    }
    sort(all(cmp)); filter(cmp);

    cout << min(solve(vec, n, m), solve(rot, m, n));

    return 0;
}

Compilation message

joioi.cpp: In function 'bool check(int)':
joioi.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int k = 0; k < cmp.size(); k++) {
      |                     ~~^~~~~~~~~~~~
joioi.cpp:27:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         while (pos + 1 < cmp.size() && cmp[pos + 1] < cmp[k] - delta) {
      |                ~~~~~~~~^~~~~~~~~~~~
joioi.cpp:29:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |             for (auto [row, col] : contain[pos]) {
      |                       ^
joioi.cpp: In function 'int solve(std::vector<std::vector<int> >&, int, int)':
joioi.cpp:59:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   59 |         for (auto [row, col] : contain[k]) {
      |                   ^
joioi.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for (int k = 0; k < cmp.size(); k++)
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 100952 KB Output is correct
2 Correct 16 ms 100952 KB Output is correct
3 Correct 16 ms 101056 KB Output is correct
4 Correct 17 ms 101096 KB Output is correct
5 Correct 17 ms 101192 KB Output is correct
6 Correct 17 ms 101048 KB Output is correct
7 Correct 17 ms 100952 KB Output is correct
8 Correct 18 ms 100956 KB Output is correct
9 Correct 17 ms 100956 KB Output is correct
10 Correct 16 ms 100952 KB Output is correct
11 Correct 20 ms 101172 KB Output is correct
12 Correct 17 ms 100996 KB Output is correct
13 Correct 17 ms 100956 KB Output is correct
14 Correct 17 ms 100956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 100952 KB Output is correct
2 Correct 16 ms 100952 KB Output is correct
3 Correct 16 ms 101056 KB Output is correct
4 Correct 17 ms 101096 KB Output is correct
5 Correct 17 ms 101192 KB Output is correct
6 Correct 17 ms 101048 KB Output is correct
7 Correct 17 ms 100952 KB Output is correct
8 Correct 18 ms 100956 KB Output is correct
9 Correct 17 ms 100956 KB Output is correct
10 Correct 16 ms 100952 KB Output is correct
11 Correct 20 ms 101172 KB Output is correct
12 Correct 17 ms 100996 KB Output is correct
13 Correct 17 ms 100956 KB Output is correct
14 Correct 17 ms 100956 KB Output is correct
15 Correct 17 ms 105304 KB Output is correct
16 Correct 23 ms 106160 KB Output is correct
17 Correct 37 ms 107224 KB Output is correct
18 Correct 37 ms 107048 KB Output is correct
19 Correct 38 ms 107128 KB Output is correct
20 Correct 35 ms 106968 KB Output is correct
21 Correct 40 ms 107224 KB Output is correct
22 Correct 43 ms 107212 KB Output is correct
23 Correct 40 ms 107216 KB Output is correct
24 Correct 37 ms 106976 KB Output is correct
25 Correct 42 ms 107224 KB Output is correct
26 Correct 39 ms 107320 KB Output is correct
27 Correct 40 ms 107224 KB Output is correct
28 Correct 39 ms 107224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 100952 KB Output is correct
2 Correct 16 ms 100952 KB Output is correct
3 Correct 16 ms 101056 KB Output is correct
4 Correct 17 ms 101096 KB Output is correct
5 Correct 17 ms 101192 KB Output is correct
6 Correct 17 ms 101048 KB Output is correct
7 Correct 17 ms 100952 KB Output is correct
8 Correct 18 ms 100956 KB Output is correct
9 Correct 17 ms 100956 KB Output is correct
10 Correct 16 ms 100952 KB Output is correct
11 Correct 20 ms 101172 KB Output is correct
12 Correct 17 ms 100996 KB Output is correct
13 Correct 17 ms 100956 KB Output is correct
14 Correct 17 ms 100956 KB Output is correct
15 Correct 17 ms 105304 KB Output is correct
16 Correct 23 ms 106160 KB Output is correct
17 Correct 37 ms 107224 KB Output is correct
18 Correct 37 ms 107048 KB Output is correct
19 Correct 38 ms 107128 KB Output is correct
20 Correct 35 ms 106968 KB Output is correct
21 Correct 40 ms 107224 KB Output is correct
22 Correct 43 ms 107212 KB Output is correct
23 Correct 40 ms 107216 KB Output is correct
24 Correct 37 ms 106976 KB Output is correct
25 Correct 42 ms 107224 KB Output is correct
26 Correct 39 ms 107320 KB Output is correct
27 Correct 40 ms 107224 KB Output is correct
28 Correct 39 ms 107224 KB Output is correct
29 Correct 1685 ms 241572 KB Output is correct
30 Correct 1596 ms 231600 KB Output is correct
31 Correct 1714 ms 247140 KB Output is correct
32 Correct 1726 ms 254636 KB Output is correct
33 Correct 1426 ms 237316 KB Output is correct
34 Correct 1743 ms 246448 KB Output is correct
35 Runtime error 1563 ms 262144 KB Execution killed with signal 9
36 Halted 0 ms 0 KB -