Submission #490740

# Submission time Handle Problem Language Result Execution time Memory
490740 2021-11-29T03:07:51 Z uHyHn The Kingdom of JOIOI (JOI17_joioi) C++14
15 / 100
54 ms 10956 KB
#include<bits/stdc++.h>

//IBOW
#define Task "KOJOIOI"
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define rep(i, b) for (int i = (1); i <= (b); ++i)
#define REP(i, b) for (int i = (b); i >= (1); --i)
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define eb emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<long long> vll;

const int N = 1e3 + 10;
const int inf = 2e9 + 10;
const ll INF = 2e18 + 10;
const int MOD = 1e9 + 7;

int n, m, a[N][N], okA[N][N], okB[N][N], min_value = inf, max_value = 0, suf[N][N], pre[N][N];

bool ok(int v)
{
    fill(&suf[0][0], &suf[0][0] + N * N, 0);
    fill(&pre[0][0], &pre[0][0] + N * N, 0);
    rep(i, n) rep(j, m) okA[i][j] = okB[i][j] = 0;
    rep(i, n) rep(j, m)
    {
        if (a[i][j] - min_value <= v) okA[i][j] = 1;
        if (max_value <= v + a[i][j]) okB[i][j] = 1;
    }
//    rep(i, n) rep(j, m) cout << okA[i][j] << " \n"[j == m];
//    cout << '\n';
//    rep(i, n) rep(j, m) cout << okB[i][j] << " \n"[j == m];
    {
        //phần A ở trên phần B ở dưới
        rep(i, n)
        {
            rep(j, m) pre[i][j] = pre[i][j - 1] + okA[i][j];
            REP(j, m) suf[i][j] = suf[i][j + 1] + okB[i][j];
        }
        {
            //phần A tăng dần
            int past_height = 0;
            rep(i, n)
            {
                bool flag = false;
                if (i == n)
                {
                    rep(j, m)
                    {
                        if (pre[i][j] == j && suf[i][j + 1] == m - j && j >= past_height)
                        {
                            flag = true;
                            past_height = j;
                            break;
                        }
                    }
                } else
                {
                    for (int j = 0; j <= m; ++j)
                    {
                        if (pre[i][j] == j && suf[i][j + 1] == m - j && j >= past_height)
                        {
                            flag = true;
                            past_height = j;
                            break;
                        }
                    }
                }
                if (flag)
                {
                    if (i == n)
                    {
//                        cout << 1 << '\n';
                        return true;
                    }
                    continue;
                }
                else break;
            }
        }
        {
            //Phần A giảm dần
            int past_height = 0;
            REP(i, n)
            {
                bool flag = false;
                if (i == n)
                {
                    rep(j, m)
                    {
                        if (pre[i][j] == j && suf[i][j + 1] == m - j && j >= past_height)
                        {
                            flag = true;
                            past_height = j;
                            break;
                        }
                    }
                } else
                {
                    for (int j = 0; j <= m; ++j)
                    {
                        if (pre[i][j] == j && suf[i][j + 1] == m - j && j >= past_height)
                        {
                            flag = true;
                            past_height = j;
                            break;
                        }
                    }
                }
                if (flag)
                {
                    if (i == 1)
                    {
//                        cout << 2 << '\n';
                        return true;
                    }
                    continue;
                }
                else break;
            }
        }
    }
    {
        //Phần B ở trên phần A ở dưới
        fill(&suf[0][0], &suf[0][0] + N * N, 0);
        fill(&pre[0][0], &pre[0][0] + N * N, 0);
        rep(i, n)
        {
            rep(j, m) pre[i][j] = pre[i][j - 1] + okB[i][j];
            REP(j, m) suf[i][j] = suf[i][j + 1] + okA[i][j];
        }
        {
            //phần B tăng dần
            int past_height = 0;
            rep(i, n)
            {
                bool flag = false;
                if (i == n)
                {
                    rep(j, m)
                    {
                        if (pre[i][j] == j && suf[i][j + 1] == m - j && j >= past_height)
                        {
                            flag = true;
                            past_height = j;
                            break;
                        }
                    }
                } else
                {
                    for (int j = 0; j <= m; ++j)
                    {
                        if (pre[i][j] == j && suf[i][j + 1] == m - j && j >= past_height)
                        {
                            flag = true;
                            past_height = j;
                            break;
                        }
                    }
                }
                if (flag)
                {
                    if (i == n)
                    {
//                        cout << 3 << '\n';
                        return true;
                    }
                    continue;
                }
                else break;
            }
        }
        {
            //Phần B giảm dần
            int past_height = 0;
            REP(i, n)
            {
                bool flag = false;
                if (i == n)
                {
                    rep(j, m)
                    {
                        if (pre[i][j] == j && suf[i][j + 1] == m - j && j >= past_height)
                        {
                            flag = true;
                            past_height = j;
                            break;
                        }
                    }
                } else
                {
                    for (int j = 0; j <= m; ++j)
                    {
                        if (pre[i][j] == j && suf[i][j + 1] == m - j && j >= past_height)
                        {
                            flag = true;
                            past_height = j;
                            break;
                        }
                    }
                }
                if (flag)
                {
                    if (i == 1)
                    {
//                        cout << 4 << '\n';
                        return true;
                    }
                    continue;
                }
                else break;
            }
        }
    }
    return false;
}
void DeoAClamcho()
{
    cin >> n >> m;
    rep(i, n) rep(j, m)
    {
        cin >> a[i][j];
        min_value = min(min_value, a[i][j]);
        max_value = max(max_value, a[i][j]);
    }
    int L = 1, R = 1e9, ans = 0;
    while (L <= R)
    {
        int mid = (L + R) / 2;
//        cout << mid << ":\n";
        if (ok(mid)) R = mid - 1, ans = mid;
        else L = mid + 1;
    }
    cout << ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(Task".inp", "r"))
    {
        freopen(Task".inp", "r", stdin);
//        freopen(Task".out", "w", stdout);
    }
    int t = 1;
    //cin >> t;
    while (t--) DeoAClamcho();
    return 0;
}



Compilation message

joioi.cpp: In function 'int32_t main()':
joioi.cpp:255:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  255 |         freopen(Task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 8268 KB Output is correct
2 Correct 19 ms 8420 KB Output is correct
3 Correct 39 ms 8408 KB Output is correct
4 Correct 42 ms 8396 KB Output is correct
5 Correct 36 ms 8396 KB Output is correct
6 Correct 26 ms 8396 KB Output is correct
7 Correct 33 ms 8396 KB Output is correct
8 Correct 27 ms 8396 KB Output is correct
9 Correct 28 ms 8396 KB Output is correct
10 Correct 35 ms 8416 KB Output is correct
11 Correct 33 ms 8372 KB Output is correct
12 Correct 39 ms 8516 KB Output is correct
13 Correct 33 ms 8396 KB Output is correct
14 Correct 42 ms 8424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 8268 KB Output is correct
2 Correct 19 ms 8420 KB Output is correct
3 Correct 39 ms 8408 KB Output is correct
4 Correct 42 ms 8396 KB Output is correct
5 Correct 36 ms 8396 KB Output is correct
6 Correct 26 ms 8396 KB Output is correct
7 Correct 33 ms 8396 KB Output is correct
8 Correct 27 ms 8396 KB Output is correct
9 Correct 28 ms 8396 KB Output is correct
10 Correct 35 ms 8416 KB Output is correct
11 Correct 33 ms 8372 KB Output is correct
12 Correct 39 ms 8516 KB Output is correct
13 Correct 33 ms 8396 KB Output is correct
14 Correct 42 ms 8424 KB Output is correct
15 Correct 22 ms 8464 KB Output is correct
16 Correct 47 ms 10704 KB Output is correct
17 Correct 43 ms 10948 KB Output is correct
18 Correct 46 ms 10956 KB Output is correct
19 Incorrect 54 ms 10884 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 8268 KB Output is correct
2 Correct 19 ms 8420 KB Output is correct
3 Correct 39 ms 8408 KB Output is correct
4 Correct 42 ms 8396 KB Output is correct
5 Correct 36 ms 8396 KB Output is correct
6 Correct 26 ms 8396 KB Output is correct
7 Correct 33 ms 8396 KB Output is correct
8 Correct 27 ms 8396 KB Output is correct
9 Correct 28 ms 8396 KB Output is correct
10 Correct 35 ms 8416 KB Output is correct
11 Correct 33 ms 8372 KB Output is correct
12 Correct 39 ms 8516 KB Output is correct
13 Correct 33 ms 8396 KB Output is correct
14 Correct 42 ms 8424 KB Output is correct
15 Correct 22 ms 8464 KB Output is correct
16 Correct 47 ms 10704 KB Output is correct
17 Correct 43 ms 10948 KB Output is correct
18 Correct 46 ms 10956 KB Output is correct
19 Incorrect 54 ms 10884 KB Output isn't correct
20 Halted 0 ms 0 KB -