Submission #752885

# Submission time Handle Problem Language Result Execution time Memory
752885 2023-06-04T07:45:20 Z bgnbvnbv The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
791 ms 63336 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=4e6+10;
const ll inf=1e18;
const ll mod=1e9+7;

ll n,m;
ll ans=inf;
ll a[2006][2006],b[2006][2006],mx=-inf,mn=inf;
bool check(ll mid)
{
    ll mxr=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(b[i][j]<mx-mid) mxr=max(mxr,1ll*j);
        }
        for(int j=1;j<=mxr;j++)
        {
            if(b[i][j]-mn>mid) return false;
        }
    }
    return true;
}
ll solve1()
{
    ll low=0,high=mx-mn-1;
    while(low<=high)
    {
        ll mid=low+high>>1;
        if(check(mid)) high=mid-1;
        else low=mid+1;
    }
    return low;
}
void rot()
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            b[m-j+1][i]=a[i][j];
        }
    }
    swap(m,n);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++) a[i][j]=b[i][j];
    }
}
void solve()
{
    cin >> n >> m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++) cin >> a[i][j],b[i][j]=a[i][j],mx=max(mx,a[i][j]),mn=min(mn,a[i][j]);
    }
    ans=min(ans,solve1());
    rot();
    ans=min(ans,solve1());
    rot();
    ans=min(ans,solve1());
    rot();
    ans=min(ans,solve1());
    cout << ans;
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

joioi.cpp: In function 'll solve1()':
joioi.cpp:38:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |         ll mid=low+high>>1;
      |                ~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 1996 KB Output is correct
16 Correct 3 ms 2516 KB Output is correct
17 Correct 6 ms 2772 KB Output is correct
18 Correct 6 ms 2772 KB Output is correct
19 Correct 7 ms 2772 KB Output is correct
20 Correct 7 ms 2772 KB Output is correct
21 Correct 8 ms 2900 KB Output is correct
22 Correct 7 ms 2852 KB Output is correct
23 Correct 9 ms 2900 KB Output is correct
24 Correct 7 ms 2772 KB Output is correct
25 Correct 10 ms 2832 KB Output is correct
26 Correct 8 ms 2900 KB Output is correct
27 Correct 8 ms 2928 KB Output is correct
28 Correct 8 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 1996 KB Output is correct
16 Correct 3 ms 2516 KB Output is correct
17 Correct 6 ms 2772 KB Output is correct
18 Correct 6 ms 2772 KB Output is correct
19 Correct 7 ms 2772 KB Output is correct
20 Correct 7 ms 2772 KB Output is correct
21 Correct 8 ms 2900 KB Output is correct
22 Correct 7 ms 2852 KB Output is correct
23 Correct 9 ms 2900 KB Output is correct
24 Correct 7 ms 2772 KB Output is correct
25 Correct 10 ms 2832 KB Output is correct
26 Correct 8 ms 2900 KB Output is correct
27 Correct 8 ms 2928 KB Output is correct
28 Correct 8 ms 2900 KB Output is correct
29 Correct 440 ms 63160 KB Output is correct
30 Correct 413 ms 63208 KB Output is correct
31 Correct 486 ms 63196 KB Output is correct
32 Correct 477 ms 63136 KB Output is correct
33 Correct 356 ms 62796 KB Output is correct
34 Correct 441 ms 63232 KB Output is correct
35 Correct 734 ms 63336 KB Output is correct
36 Correct 598 ms 62932 KB Output is correct
37 Correct 791 ms 63292 KB Output is correct