답안 #376891

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
376891 2021-03-12T06:15:59 Z astoria The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
3320 ms 31340 KB
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
 
const int H=2005,W=2005;
int h,w,lo,hi;
int g[H][W];
 
bool check(int x){
	int losen=w+1;
	for(int i=1; i<=h; i++){
		int lopo=0;
		for(int j=1; j<=w; j++){
			if(lo+x < g[i][j]) break;
			lopo++;
		}
		losen=min(losen,lopo);
		int hipo=w+1;
		for(int j=w; j>=1; j--){
			if(hi-x > g[i][j]) break;
			hipo--;
		}
		if(losen + 1 < hipo) return 0;
	}
	return 1;
}
 
void flip_row(){
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w/2; j++){
			swap(g[i][j],g[i][w-j+1]);
		}
	}
}
 
void flip_col(){
	for(int j=1; j<=w; j++){
		for(int i=1; i<=h/2; i++){
			swap(g[i][j],g[h-i+1][j]);
		}
	}
}
 
bool f(int x){
	bool an=0;
	if(check(x)) an=1;
	flip_row();
	if(check(x)) an=1;
	flip_col();
	if(check(x)) an=1;
	flip_row();
	if(check(x)) an=1;
	flip_col();
	return an;
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>h>>w;
	lo=1e9+500; hi=-1e6;
	for(int j=0; j<=w+1; j++) g[0][j]=0;
	for(int i=1; i<=h; i++){
		g[i][0]=0;
		for(int j=1; j<=w; j++){
			cin>>g[i][j];
			lo=min(lo,g[i][j]);
			hi=max(hi,g[i][j]);
		}
		g[i][w+1]=0;
	}
	for(int j=0; j<=w+1; j++) g[h+1][j]=0;
	
	int l=0, r=1e9+100;
	while(l<r){
		int m=l+((r-l)/2);
		if(f(m)) r=m;
		else l=m+1;
	}
	cout<<l;
	
	//checkc(5);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 12 ms 1388 KB Output is correct
17 Correct 12 ms 1536 KB Output is correct
18 Correct 10 ms 1516 KB Output is correct
19 Correct 10 ms 1516 KB Output is correct
20 Correct 9 ms 1388 KB Output is correct
21 Correct 11 ms 1644 KB Output is correct
22 Correct 9 ms 1644 KB Output is correct
23 Correct 9 ms 1792 KB Output is correct
24 Correct 8 ms 1516 KB Output is correct
25 Correct 11 ms 1644 KB Output is correct
26 Correct 9 ms 1644 KB Output is correct
27 Correct 14 ms 1644 KB Output is correct
28 Correct 12 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 12 ms 1388 KB Output is correct
17 Correct 12 ms 1536 KB Output is correct
18 Correct 10 ms 1516 KB Output is correct
19 Correct 10 ms 1516 KB Output is correct
20 Correct 9 ms 1388 KB Output is correct
21 Correct 11 ms 1644 KB Output is correct
22 Correct 9 ms 1644 KB Output is correct
23 Correct 9 ms 1792 KB Output is correct
24 Correct 8 ms 1516 KB Output is correct
25 Correct 11 ms 1644 KB Output is correct
26 Correct 9 ms 1644 KB Output is correct
27 Correct 14 ms 1644 KB Output is correct
28 Correct 12 ms 1644 KB Output is correct
29 Correct 3085 ms 20520 KB Output is correct
30 Correct 3091 ms 22816 KB Output is correct
31 Correct 3320 ms 21228 KB Output is correct
32 Correct 3316 ms 21444 KB Output is correct
33 Correct 2806 ms 31340 KB Output is correct
34 Correct 3312 ms 21348 KB Output is correct
35 Correct 3230 ms 24836 KB Output is correct
36 Correct 2797 ms 22572 KB Output is correct
37 Correct 3189 ms 24984 KB Output is correct