Submission #598777

# Submission time Handle Problem Language Result Execution time Memory
598777 2022-07-19T03:54:30 Z Hanksburger The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
604 ms 54812 KB
#include <bits/stdc++.h>
using namespace std;
int a[2005][2005], b[2005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, mn=1e9, mx=0, ans=1e9;
    cin >> n >> m;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=m; j++)
        {
            cin >> a[i][j];
            mn=min(mn, a[i][j]);
            mx=max(mx, a[i][j]);
        }
    }
    b[0]=m+1;
    for (int y=2; y--; )
    {
        for (int z=2; z--; )
        {
            int l=0, r=1e9;
            while (l<r)
            {
                int mid=(l+r)/2;
                bool ok=1;
                for (int i=1; i<=n; i++)
                {
                    for (int j=1; j<=m; j++)
                    {
                        if (j==b[i-1] || a[i][j]>mn+mid)
                        {
                            b[i]=j;
                            break;
                        }
                        if (j==m)
                        {
                            b[i]=j+1;
                            break;
                        }
                    }
                    for (int j=b[i]; j<=m; j++)
                    {
                        if (a[i][j]<mx-mid)
                        {
                            ok=0;
                            break;
                        }
                    }
                    if (!ok)
                        break;
                }
                if (ok)
                    r=mid;
                else
                    l=mid+1;
            }
            ans=min(ans, l);
            for (int i=1; i<=n; i++)
                for (int j=1; j<=m/2; j++)
                    swap(a[i][j], a[i][m+1-j]);
        }
        for (int i=1; i<=m; i++)
            for (int j=1; j<=n/2; j++)
                swap(a[j][i], a[n+1-j][i]);
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 7 ms 1236 KB Output is correct
17 Correct 7 ms 1496 KB Output is correct
18 Correct 7 ms 1496 KB Output is correct
19 Correct 8 ms 1488 KB Output is correct
20 Correct 7 ms 1364 KB Output is correct
21 Correct 7 ms 1620 KB Output is correct
22 Correct 7 ms 1624 KB Output is correct
23 Correct 7 ms 1608 KB Output is correct
24 Correct 6 ms 1460 KB Output is correct
25 Correct 7 ms 1620 KB Output is correct
26 Correct 6 ms 1608 KB Output is correct
27 Correct 8 ms 1620 KB Output is correct
28 Correct 10 ms 1604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 7 ms 1236 KB Output is correct
17 Correct 7 ms 1496 KB Output is correct
18 Correct 7 ms 1496 KB Output is correct
19 Correct 8 ms 1488 KB Output is correct
20 Correct 7 ms 1364 KB Output is correct
21 Correct 7 ms 1620 KB Output is correct
22 Correct 7 ms 1624 KB Output is correct
23 Correct 7 ms 1608 KB Output is correct
24 Correct 6 ms 1460 KB Output is correct
25 Correct 7 ms 1620 KB Output is correct
26 Correct 6 ms 1608 KB Output is correct
27 Correct 8 ms 1620 KB Output is correct
28 Correct 10 ms 1604 KB Output is correct
29 Correct 557 ms 37276 KB Output is correct
30 Correct 550 ms 37500 KB Output is correct
31 Correct 567 ms 39096 KB Output is correct
32 Correct 583 ms 39052 KB Output is correct
33 Correct 538 ms 34028 KB Output is correct
34 Correct 582 ms 39292 KB Output is correct
35 Correct 604 ms 54680 KB Output is correct
36 Correct 488 ms 49520 KB Output is correct
37 Correct 552 ms 54812 KB Output is correct