# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
549532 | 2022-04-16T02:37:19 Z | krit3379 | The Kingdom of JOIOI (JOI17_joioi) | C++17 | 2894 ms | 71060 KB |
#include<bits/stdc++.h> using namespace std; #define N 2005 int a[N][N],b[N][N],ans=2e9; bool valid(int n,int m,int val,int &ans){ int i,j,mi[2],ma[2]; bitset<N> dp[N]; mi[0]=mi[1]=1e9; ma[0]=ma[1]=0; for(i=0;i<=m;i++)dp[n+1][i]=true; for(i=0;i<=n;i++)dp[i]=1; for(i=n;i>0;i--)for(j=1;a[i][j]<=val&&dp[i+1][j]&&dp[i][j-1];j++)dp[i][j]=true; if(dp[1][m])return true; if(!dp[n][1])return false; for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ mi[dp[i][j]]=min(mi[dp[i][j]],a[i][j]); ma[dp[i][j]]=max(ma[dp[i][j]],a[i][j]); } } ans=min(ans,max(ma[0]-mi[0],ma[1]-mi[1])); if(mi[1]>=mi[0])return false; return ma[1]-mi[1]>ma[0]-mi[0]; } int sol(int n,int m){ int l=0,r=1e9,mid,ans=1e9; while(l<=r){ mid=(l+r)/2; if(valid(n,m,mid,ans))r=mid-1; else l=mid+1; } return ans; } int main(){ int n,m,i,j,k,mi=2e9,ma=0; scanf("%d %d",&n,&m); for(i=1;i<=n;i++)for(j=1;j<=m;j++)scanf("%d",&a[i][j]); ans=min(ans,sol(n,m)); for(i=1;i<=n;i++)for(j=1;j<=m;j++)b[i][j]=a[i][j]; for(i=1;i<=m;i++)for(j=1;j<=n;j++)a[i][j]=b[n-j+1][i]; ans=min(ans,sol(m,n)); for(i=1;i<=m;i++)for(j=1;j<=n;j++)b[i][j]=a[i][j]; for(i=1;i<=n;i++)for(j=1;j<=m;j++)a[i][j]=b[m-j+1][i]; ans=min(ans,sol(n,m)); for(i=1;i<=n;i++)for(j=1;j<=m;j++)b[i][j]=a[i][j]; for(i=1;i<=m;i++)for(j=1;j<=n;j++)a[i][j]=b[n-j+1][i]; ans=min(ans,sol(m,n)); printf("%d",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 852 KB | Output is correct |
2 | Correct | 2 ms | 820 KB | Output is correct |
3 | Correct | 2 ms | 824 KB | Output is correct |
4 | Correct | 3 ms | 892 KB | Output is correct |
5 | Correct | 3 ms | 852 KB | Output is correct |
6 | Correct | 3 ms | 852 KB | Output is correct |
7 | Correct | 3 ms | 852 KB | Output is correct |
8 | Correct | 3 ms | 908 KB | Output is correct |
9 | Correct | 3 ms | 824 KB | Output is correct |
10 | Correct | 4 ms | 852 KB | Output is correct |
11 | Correct | 3 ms | 852 KB | Output is correct |
12 | Correct | 3 ms | 832 KB | Output is correct |
13 | Correct | 2 ms | 852 KB | Output is correct |
14 | Correct | 3 ms | 828 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 852 KB | Output is correct |
2 | Correct | 2 ms | 820 KB | Output is correct |
3 | Correct | 2 ms | 824 KB | Output is correct |
4 | Correct | 3 ms | 892 KB | Output is correct |
5 | Correct | 3 ms | 852 KB | Output is correct |
6 | Correct | 3 ms | 852 KB | Output is correct |
7 | Correct | 3 ms | 852 KB | Output is correct |
8 | Correct | 3 ms | 908 KB | Output is correct |
9 | Correct | 3 ms | 824 KB | Output is correct |
10 | Correct | 4 ms | 852 KB | Output is correct |
11 | Correct | 3 ms | 852 KB | Output is correct |
12 | Correct | 3 ms | 832 KB | Output is correct |
13 | Correct | 2 ms | 852 KB | Output is correct |
14 | Correct | 3 ms | 828 KB | Output is correct |
15 | Correct | 4 ms | 2388 KB | Output is correct |
16 | Correct | 17 ms | 2772 KB | Output is correct |
17 | Correct | 24 ms | 2912 KB | Output is correct |
18 | Correct | 26 ms | 3008 KB | Output is correct |
19 | Correct | 31 ms | 2952 KB | Output is correct |
20 | Correct | 25 ms | 2940 KB | Output is correct |
21 | Correct | 32 ms | 3108 KB | Output is correct |
22 | Correct | 31 ms | 3156 KB | Output is correct |
23 | Correct | 32 ms | 3020 KB | Output is correct |
24 | Correct | 26 ms | 3028 KB | Output is correct |
25 | Correct | 33 ms | 3108 KB | Output is correct |
26 | Correct | 34 ms | 3020 KB | Output is correct |
27 | Correct | 35 ms | 3104 KB | Output is correct |
28 | Correct | 32 ms | 3028 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 852 KB | Output is correct |
2 | Correct | 2 ms | 820 KB | Output is correct |
3 | Correct | 2 ms | 824 KB | Output is correct |
4 | Correct | 3 ms | 892 KB | Output is correct |
5 | Correct | 3 ms | 852 KB | Output is correct |
6 | Correct | 3 ms | 852 KB | Output is correct |
7 | Correct | 3 ms | 852 KB | Output is correct |
8 | Correct | 3 ms | 908 KB | Output is correct |
9 | Correct | 3 ms | 824 KB | Output is correct |
10 | Correct | 4 ms | 852 KB | Output is correct |
11 | Correct | 3 ms | 852 KB | Output is correct |
12 | Correct | 3 ms | 832 KB | Output is correct |
13 | Correct | 2 ms | 852 KB | Output is correct |
14 | Correct | 3 ms | 828 KB | Output is correct |
15 | Correct | 4 ms | 2388 KB | Output is correct |
16 | Correct | 17 ms | 2772 KB | Output is correct |
17 | Correct | 24 ms | 2912 KB | Output is correct |
18 | Correct | 26 ms | 3008 KB | Output is correct |
19 | Correct | 31 ms | 2952 KB | Output is correct |
20 | Correct | 25 ms | 2940 KB | Output is correct |
21 | Correct | 32 ms | 3108 KB | Output is correct |
22 | Correct | 31 ms | 3156 KB | Output is correct |
23 | Correct | 32 ms | 3020 KB | Output is correct |
24 | Correct | 26 ms | 3028 KB | Output is correct |
25 | Correct | 33 ms | 3108 KB | Output is correct |
26 | Correct | 34 ms | 3020 KB | Output is correct |
27 | Correct | 35 ms | 3104 KB | Output is correct |
28 | Correct | 32 ms | 3028 KB | Output is correct |
29 | Correct | 1970 ms | 54300 KB | Output is correct |
30 | Correct | 1869 ms | 53700 KB | Output is correct |
31 | Correct | 1988 ms | 55320 KB | Output is correct |
32 | Correct | 1965 ms | 55288 KB | Output is correct |
33 | Correct | 1845 ms | 52148 KB | Output is correct |
34 | Correct | 2027 ms | 55400 KB | Output is correct |
35 | Correct | 2894 ms | 70948 KB | Output is correct |
36 | Correct | 2527 ms | 65864 KB | Output is correct |
37 | Correct | 2857 ms | 71060 KB | Output is correct |