답안 #1007401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007401 2024-06-24T19:04:02 Z giorgi_pkhaladze The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1468 ms 70864 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ff first
#define ss second
using namespace std;
const int N=2010;
int n,m,ans,a[N][N],b[N][N],mn;
void turn(){
	for(int i=1; i<=n; i++) for(int j = 1; j<=m; j++)b[j][n+1-i]=a[i][j];
	swap(n,m);
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++)a[i][j]=b[i][j];
}
bool check(int o){
	for(int k=0; k<4; k++){
		int lst=m,omx=0,omn=1e9;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= lst; j++)if(a[i][j]>mn+o){lst=j-1; break;}
			for(int j=lst+1; j<=m; j++){
				omx=max(omx,a[i][j]);
				omn=min(omn,a[i][j]);
			}
		}
		if(omx-omn<=o)return 1;
		if(k<3) turn();
	}
	return 0;
}
int main() {
	cin>>n>>m;
	mn=1e9;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++){cin>>a[i][j]; mn=min(mn,a[i][j]);}
	int l=0,r=1e9;
	while(l<=r){
		int md=(l+r)/2;
		if(check(md))r=md-1;
		else l=md+1;
	}
	cout<<l;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2488 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2488 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 5 ms 6748 KB Output is correct
17 Correct 10 ms 6864 KB Output is correct
18 Correct 12 ms 7112 KB Output is correct
19 Correct 11 ms 6984 KB Output is correct
20 Correct 12 ms 6828 KB Output is correct
21 Correct 16 ms 7100 KB Output is correct
22 Correct 17 ms 7004 KB Output is correct
23 Correct 15 ms 6952 KB Output is correct
24 Correct 14 ms 7004 KB Output is correct
25 Correct 14 ms 6980 KB Output is correct
26 Correct 15 ms 7004 KB Output is correct
27 Correct 15 ms 6952 KB Output is correct
28 Correct 15 ms 6952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2488 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 5 ms 6748 KB Output is correct
17 Correct 10 ms 6864 KB Output is correct
18 Correct 12 ms 7112 KB Output is correct
19 Correct 11 ms 6984 KB Output is correct
20 Correct 12 ms 6828 KB Output is correct
21 Correct 16 ms 7100 KB Output is correct
22 Correct 17 ms 7004 KB Output is correct
23 Correct 15 ms 6952 KB Output is correct
24 Correct 14 ms 7004 KB Output is correct
25 Correct 14 ms 6980 KB Output is correct
26 Correct 15 ms 7004 KB Output is correct
27 Correct 15 ms 6952 KB Output is correct
28 Correct 15 ms 6952 KB Output is correct
29 Correct 882 ms 54112 KB Output is correct
30 Correct 897 ms 53280 KB Output is correct
31 Correct 888 ms 54848 KB Output is correct
32 Correct 861 ms 54868 KB Output is correct
33 Correct 839 ms 51864 KB Output is correct
34 Correct 936 ms 54960 KB Output is correct
35 Correct 1468 ms 70680 KB Output is correct
36 Correct 1212 ms 65340 KB Output is correct
37 Correct 1410 ms 70864 KB Output is correct