Submission #205598

# Submission time Handle Problem Language Result Execution time Memory
205598 2020-02-29T09:25:23 Z Kastanda The Kingdom of JOIOI (JOI17_joioi) C++11
100 / 100
3453 ms 16288 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)
{
    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 = Val[1] - Val[0], 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:74: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:77: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 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 380 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 376 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 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 380 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 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 13 ms 1272 KB Output is correct
17 Correct 33 ms 1404 KB Output is correct
18 Correct 31 ms 1272 KB Output is correct
19 Correct 28 ms 1272 KB Output is correct
20 Correct 26 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 42 ms 1272 KB Output is correct
24 Correct 33 ms 1144 KB Output is correct
25 Correct 38 ms 1272 KB Output is correct
26 Correct 39 ms 1316 KB Output is correct
27 Correct 40 ms 1272 KB Output is correct
28 Correct 41 ms 1316 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 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 380 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 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 13 ms 1272 KB Output is correct
17 Correct 33 ms 1404 KB Output is correct
18 Correct 31 ms 1272 KB Output is correct
19 Correct 28 ms 1272 KB Output is correct
20 Correct 26 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 42 ms 1272 KB Output is correct
24 Correct 33 ms 1144 KB Output is correct
25 Correct 38 ms 1272 KB Output is correct
26 Correct 39 ms 1316 KB Output is correct
27 Correct 40 ms 1272 KB Output is correct
28 Correct 41 ms 1316 KB Output is correct
29 Correct 2150 ms 15324 KB Output is correct
30 Correct 2099 ms 16192 KB Output is correct
31 Correct 2227 ms 16180 KB Output is correct
32 Correct 2285 ms 16196 KB Output is correct
33 Correct 1992 ms 14252 KB Output is correct
34 Correct 2253 ms 16120 KB Output is correct
35 Correct 3453 ms 16288 KB Output is correct
36 Correct 3064 ms 16120 KB Output is correct
37 Correct 3335 ms 16276 KB Output is correct