Submission #906279

# Submission time Handle Problem Language Result Execution time Memory
906279 2024-01-13T22:43:57 Z Maite_Morale The Kingdom of JOIOI (JOI17_joioi) C++14
60 / 100
2953 ms 262144 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define MAX 3005
#define oo 1e18
#define mod 1000000007
#define fast_in ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(0);
using namespace std;
typedef long long ll;
#define pll pair<ll , ll>
#define vll vector<ll>
#define vvll vector<vll>
#define vpll vector<pll>
    
ll tmn[5][MAX][MAX],tmx[5][MAX][MAX],n,a[MAX][MAX],m;
map<ll,ll> mp;
vll v;
ll OK(ll x,ll z){
    //cout<<x<<":  ";
    ll r=oo,mx=0,c=0;
    for(int i=1;i<=n;i++){
        while(c+1<=m && tmn[1][i][c+1]<x)c++;
        mx=max(mx,tmx[0][i][c]);
    }r=min(r,mx);
    //cout<<mx<<"  ";
    mx=0;c=0;
    for(int i=n;i>0;i--){
        while(c+1<=m && tmn[1][i][c+1]<x)c++;
        mx=max(mx,tmx[0][i][c]);
    }r=min(r,mx);
    //cout<<mx<<" ";
    mx=0;c=m+1;
    for(int i=1;i<=n;i++){
        while(c-1>=0 && tmn[0][i][c-1]<x)c--;
        mx=max(mx,tmx[1][i][c]);
    }r=min(r,mx);
    //cout<<mx<<" ";
    mx=0;c=m+1;
    for(int i=n;i>0;i--){
        while(c-1>=0 && tmn[0][i][c-1]<x)c--;
        mx=max(mx,tmx[1][i][c]);
    }r=min(r,mx);
    //cout<<mx<<"\n";
    if(z==1)return max(abs(r-v[0]),abs(v.back()-x));
    if(abs(r-v[0])>=abs(v.back()-x))return 0;
return 1;
}
int main(){
    fast_in
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            if(mp[a[i][j]]==0){
                mp[a[i][j]]=1;
                v.push_back(a[i][j]);
            }
        }
        tmx[0][i][0]=tmx[1][i][m+1]=0;
        tmn[0][i][0]=tmn[1][i][m+1]=oo;
        for(int j=1;j<=m;j++){
            tmx[0][i][j]=max(tmx[0][i][j-1],a[i][j]);
            tmn[0][i][j]=min(tmn[0][i][j-1],a[i][j]);
            
        }
        for(int j=m;j>0;j--){
            tmx[1][i][j]=max(tmx[1][i][j+1],a[i][j]);
            tmn[1][i][j]=min(tmn[1][i][j+1],a[i][j]);
            //cout<<tmn[1][i][j]<<" ";
        }//cout<<"\n";
    }sort(v.begin(),v.end());
    if(v.size()==1){cout<<0;return 0;}
    ll p=1,f=v.size();//cout<<f<<" ";
    while(abs(p-f)!=1){
        ll md=(p+f)/2;//cout<<md<<":";
        if(OK(v[md],0)==1)p=md;
        else            f=md;
    }
    cout<<min(OK(v[p],1),OK(v[f],1));
return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 3 ms 10584 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 3 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 3 ms 10700 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10584 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 3 ms 10584 KB Output is correct
14 Correct 3 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 3 ms 10584 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 3 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 3 ms 10700 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10584 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 3 ms 10584 KB Output is correct
14 Correct 3 ms 10588 KB Output is correct
15 Correct 3 ms 10708 KB Output is correct
16 Correct 9 ms 33372 KB Output is correct
17 Correct 24 ms 36560 KB Output is correct
18 Correct 24 ms 36292 KB Output is correct
19 Correct 25 ms 36296 KB Output is correct
20 Correct 22 ms 31692 KB Output is correct
21 Correct 29 ms 36300 KB Output is correct
22 Correct 26 ms 36308 KB Output is correct
23 Correct 31 ms 36376 KB Output is correct
24 Correct 23 ms 31856 KB Output is correct
25 Correct 25 ms 36304 KB Output is correct
26 Correct 25 ms 36304 KB Output is correct
27 Correct 28 ms 36432 KB Output is correct
28 Correct 28 ms 36472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 3 ms 10584 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 3 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 3 ms 10700 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10584 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 3 ms 10584 KB Output is correct
14 Correct 3 ms 10588 KB Output is correct
15 Correct 3 ms 10708 KB Output is correct
16 Correct 9 ms 33372 KB Output is correct
17 Correct 24 ms 36560 KB Output is correct
18 Correct 24 ms 36292 KB Output is correct
19 Correct 25 ms 36296 KB Output is correct
20 Correct 22 ms 31692 KB Output is correct
21 Correct 29 ms 36300 KB Output is correct
22 Correct 26 ms 36308 KB Output is correct
23 Correct 31 ms 36376 KB Output is correct
24 Correct 23 ms 31856 KB Output is correct
25 Correct 25 ms 36304 KB Output is correct
26 Correct 25 ms 36304 KB Output is correct
27 Correct 28 ms 36432 KB Output is correct
28 Correct 28 ms 36472 KB Output is correct
29 Correct 1243 ms 259420 KB Output is correct
30 Correct 1192 ms 262144 KB Output is correct
31 Correct 1158 ms 262144 KB Output is correct
32 Correct 1196 ms 262144 KB Output is correct
33 Correct 979 ms 239816 KB Output is correct
34 Correct 1204 ms 262144 KB Output is correct
35 Runtime error 2953 ms 262144 KB Execution killed with signal 9
36 Halted 0 ms 0 KB -