Submission #706362

# Submission time Handle Problem Language Result Execution time Memory
706362 2023-03-06T10:30:34 Z Baytoro The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
2048 ms 86196 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=998244353;
const int N=2005;
int a[N][N],tmp[N][N];

int n,m;
int calc(int x){
	int mn=INF,mx=-INF;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
			mn=min(mn,tmp[i][j]),mx=max(mx,tmp[i][j]);
	}
	for(int i=1, l=m+1;i<=n;i++){
		for(int j=1;j<l;j++){
			if(tmp[i][j]-mn>x){
				l=j;
				break;
			}
		}
		for(int j=l;j<=m;j++){
			if(mx-tmp[i][j]>x) return false;
		}
	}
	return true;
}
int check(int x){
	for(int i=1;i<=n;i++) 
		for(int j=1;j<=m;j++) 
			tmp[i][j]=a[i][j];
	for(int I=0;I<2;I++){
		for(int J=0;J<2;J++){
			if(calc(x)) return true;
			for(int i=1;i<=n;i++){
				for(int l=1,r=m;l<r;l++,r--){
					swap(tmp[i][l],tmp[i][r]);
				}
			}
		}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				tmp[i][j]=-tmp[i][j];
	}
	return false;
}
void solve(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	int l=-1,r=1e9;
	while(r-l>1){
		int md=(l+r)/2;
		if(check(md)) r=md;
		else l=md;
	}
	cout<<r;
	
}
main(){
	//fopn("cbarn");
	ios;
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
}

Compilation message

joioi.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main(){
      | ^~~~
joioi.cpp: In function 'void fopn(std::string)':
joioi.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joioi.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 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 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 324 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 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 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 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 324 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 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 10 ms 2516 KB Output is correct
17 Correct 11 ms 2772 KB Output is correct
18 Correct 11 ms 2828 KB Output is correct
19 Correct 16 ms 2772 KB Output is correct
20 Correct 14 ms 2544 KB Output is correct
21 Correct 13 ms 2904 KB Output is correct
22 Correct 16 ms 2932 KB Output is correct
23 Correct 12 ms 2928 KB Output is correct
24 Correct 12 ms 2640 KB Output is correct
25 Correct 13 ms 2916 KB Output is correct
26 Correct 22 ms 2900 KB Output is correct
27 Correct 18 ms 2900 KB Output is correct
28 Correct 35 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 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 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 324 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 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 10 ms 2516 KB Output is correct
17 Correct 11 ms 2772 KB Output is correct
18 Correct 11 ms 2828 KB Output is correct
19 Correct 16 ms 2772 KB Output is correct
20 Correct 14 ms 2544 KB Output is correct
21 Correct 13 ms 2904 KB Output is correct
22 Correct 16 ms 2932 KB Output is correct
23 Correct 12 ms 2928 KB Output is correct
24 Correct 12 ms 2640 KB Output is correct
25 Correct 13 ms 2916 KB Output is correct
26 Correct 22 ms 2900 KB Output is correct
27 Correct 18 ms 2900 KB Output is correct
28 Correct 35 ms 2936 KB Output is correct
29 Correct 1312 ms 82004 KB Output is correct
30 Correct 1535 ms 84568 KB Output is correct
31 Correct 1344 ms 86132 KB Output is correct
32 Correct 1250 ms 86140 KB Output is correct
33 Correct 1053 ms 75412 KB Output is correct
34 Correct 1563 ms 86196 KB Output is correct
35 Correct 1836 ms 73796 KB Output is correct
36 Correct 1700 ms 71420 KB Output is correct
37 Correct 2048 ms 81296 KB Output is correct