Submission #205596

# Submission time Handle Problem Language Result Execution time Memory
205596 2020-02-29T09:23:31 Z Kastanda The Kingdom of JOIOI (JOI17_joioi) C++11
100 / 100
3615 ms 33272 KB
// In The Name Of The Queen
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimzie("O3")
using namespace std;
const int N = 2019, INF = 1e9 + 1;
int n, m, A[N][N], P[N], S[N], B[N];
pair < int , int > At[2];
int Val[2];
inline int Solve(int md)
{
    // Pref has Val[0], so we're keeping track of the maximum in it.
    for (int w = 0; w <= 1; w ++)
    {
        P[0] = 0; S[m + 1] = INF;
        for (int i = 1; i <= n; i ++)
        {
            for (int j = 1; j <= m; j ++)
                P[j] = max(P[j - 1], A[i][j]);
            for (int j = m; j; j --)
                S[j] = min(S[j + 1], A[i][j]);
            B[i] = m + 1;
            int l = B[i - 1], r = m;
            if (At[0].first == i)
                l = max(l, At[0].second);
            if (At[1].first == i)
                r = min(r, At[1].second - 1);
            for (int j = l; j <= r; j ++)
            {
                if (P[j] - Val[0] > md)
                    break;
                if (Val[1] - S[j + 1] > md)
                    continue;
                B[i] = j;
                break;
            }
        }
        if (B[n] <= m)
            return 1;
        for (int i = 1; i <= n; i ++)
            for (int j = 1; j <= m; j ++)
                A[i][j] = INF - A[i][j];
        Val[0] = INF - Val[0];
        Val[1] = INF - Val[1];
        swap(Val[0], Val[1]);
        swap(At[0], At[1]);
    }
    return 0;
}
inline int Run()
{
    Val[0] = INT_MAX;
    Val[1] = INT_MIN;
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++)
        {
            if (Val[0] > A[i][j])
                Val[0] = A[i][j], At[0] = {i, j};
            if (Val[1] < A[i][j])
                Val[1] = A[i][j], At[1] = {i, j};
        }
    int le = -1, ri = (int)(1e9), md;
    while (ri - le > 1)
    {
        md = (le + ri) >> 1;
        if (Solve(md))
            ri = md;
        else
            le = md;
    }
    return (ri);
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++)
            scanf("%d", &A[i][j]);
    int Mn = Run();
    for (int i = 1; i < n - i + 1; i ++)
        for (int j = 1; j <= m; j ++)
            swap(A[i][j], A[n - i + 1][j]);
    Mn = min(Mn, Run());
    return !printf("%d\n", Mn);
}

Compilation message

joioi.cpp:4:0: warning: ignoring #pragma GCC optimzie [-Wunknown-pragmas]
 #pragma GCC optimzie("O3")
 
joioi.cpp: In function 'int main()':
joioi.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
joioi.cpp:78:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &A[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 24 ms 1272 KB Output is correct
17 Correct 31 ms 1276 KB Output is correct
18 Correct 31 ms 1276 KB Output is correct
19 Correct 31 ms 1272 KB Output is correct
20 Correct 29 ms 1144 KB Output is correct
21 Correct 39 ms 1272 KB Output is correct
22 Correct 39 ms 1272 KB Output is correct
23 Correct 36 ms 1272 KB Output is correct
24 Correct 33 ms 1144 KB Output is correct
25 Correct 38 ms 1276 KB Output is correct
26 Correct 39 ms 1272 KB Output is correct
27 Correct 39 ms 1272 KB Output is correct
28 Correct 40 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 24 ms 1272 KB Output is correct
17 Correct 31 ms 1276 KB Output is correct
18 Correct 31 ms 1276 KB Output is correct
19 Correct 31 ms 1272 KB Output is correct
20 Correct 29 ms 1144 KB Output is correct
21 Correct 39 ms 1272 KB Output is correct
22 Correct 39 ms 1272 KB Output is correct
23 Correct 36 ms 1272 KB Output is correct
24 Correct 33 ms 1144 KB Output is correct
25 Correct 38 ms 1276 KB Output is correct
26 Correct 39 ms 1272 KB Output is correct
27 Correct 39 ms 1272 KB Output is correct
28 Correct 40 ms 1272 KB Output is correct
29 Correct 2574 ms 15592 KB Output is correct
30 Correct 2472 ms 16220 KB Output is correct
31 Correct 2606 ms 16180 KB Output is correct
32 Correct 2693 ms 16200 KB Output is correct
33 Correct 2356 ms 14260 KB Output is correct
34 Correct 2620 ms 16268 KB Output is correct
35 Correct 3370 ms 16308 KB Output is correct
36 Correct 3081 ms 30860 KB Output is correct
37 Correct 3615 ms 33272 KB Output is correct