답안 #309500

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
309500 2020-10-03T17:14:26 Z JovanK26 The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1195 ms 55048 KB
#include <bits/stdc++.h>

using namespace std;
int mat[2001][2001];
int n,m;
int maks=0;
int mini=1000000000;
bool check(int med)
{
     int pos=0;
     for(int i=0;i<n;i++)
     {
         for(int j=0;j<m;j++)
         {
             if(mat[i][j]+med<maks)
             {
                 pos=max(pos,j+1);
             }
         }
         for(int j=0;j<m;j++)
         {
             if(mat[i][j]-med>mini)
             {
                 if(j<pos)return 0;
             }
         }
     }
     return 1;
}
void fliprow()
{
    for(int i=0;i<n/2;i++)
    {
        for(int j=0;j<m;j++)
        {
            swap(mat[i][j],mat[n-i-1][j]);
        }
    }
}
void flipcol()
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m/2;j++)
        {
            swap(mat[i][j],mat[i][m-j-1]);
        }
    }
}
int solve()
{
    int l=0;
    int r=maks-mini;
    int med;
    while(l<=r)
    {
        med=(l+r)/2;
        if(check(med))
        {
            r=med-1;
        }
        else
        {
            l=med+1;
        }
    }
    return r+1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin >> mat[i][j];
            maks=max(maks,mat[i][j]);
            mini=min(mini,mat[i][j]);
        }
    }
    int rez=solve();
    fliprow();
    rez=min(rez,solve());
    flipcol();
    rez=min(rez,solve());
    fliprow();
    rez=min(rez,solve());
    cout << rez;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1316 KB Output is correct
17 Correct 8 ms 1536 KB Output is correct
18 Correct 9 ms 1568 KB Output is correct
19 Correct 10 ms 1696 KB Output is correct
20 Correct 8 ms 1408 KB Output is correct
21 Correct 11 ms 1664 KB Output is correct
22 Correct 12 ms 1664 KB Output is correct
23 Correct 16 ms 1664 KB Output is correct
24 Correct 11 ms 1536 KB Output is correct
25 Correct 17 ms 1664 KB Output is correct
26 Correct 14 ms 1664 KB Output is correct
27 Correct 12 ms 1664 KB Output is correct
28 Correct 10 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1316 KB Output is correct
17 Correct 8 ms 1536 KB Output is correct
18 Correct 9 ms 1568 KB Output is correct
19 Correct 10 ms 1696 KB Output is correct
20 Correct 8 ms 1408 KB Output is correct
21 Correct 11 ms 1664 KB Output is correct
22 Correct 12 ms 1664 KB Output is correct
23 Correct 16 ms 1664 KB Output is correct
24 Correct 11 ms 1536 KB Output is correct
25 Correct 17 ms 1664 KB Output is correct
26 Correct 14 ms 1664 KB Output is correct
27 Correct 12 ms 1664 KB Output is correct
28 Correct 10 ms 1664 KB Output is correct
29 Correct 496 ms 37556 KB Output is correct
30 Correct 547 ms 37496 KB Output is correct
31 Correct 681 ms 39160 KB Output is correct
32 Correct 474 ms 39160 KB Output is correct
33 Correct 423 ms 34168 KB Output is correct
34 Correct 581 ms 39416 KB Output is correct
35 Correct 969 ms 54904 KB Output is correct
36 Correct 861 ms 49784 KB Output is correct
37 Correct 1195 ms 55048 KB Output is correct