답안 #396800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396800 2021-04-30T18:45:51 Z keta_tsimakuridze The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1354 ms 95156 KB
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N=2e3+5,mod=1e9+7;
int t,a[N][N],r[N],l[N],n,m,ans;
map<int,int> fix;
vector<int> val,val1;
string s;

bool check(int mx1){
	int diff=mx1-val[0];
	for(int i=1;i<=n;i++) {
		l[i]=m+1;  r[i]=0;
	}
	for(int i=1;i<=n;i++) {
		for(int j=m;j>=1;j--){
			if(a[i][j]>mx1) l[i] = j - 1;
		}
		for(int j=1;j<=m;j++){
			if(a[i][j]+diff<val.back()) r[i] = j ;
		}
		 // [r[i] , l[i]) 
		 if(l[i]<r[i]) return 0;
	}
	int F=0;
	int cur=m;
	for(int i=1;i<=n;i++) {
		if(r[i]>cur) {
			F=1;
			break;
		} 
		cur = min(l[i],cur);
	}
	if(!F) return 1; 
	F=0;
	cur=0;
	for(int i=1;i<=n;i++) {
		if(l[i]<cur) {
			F=1;
			break;
		}
		cur = max(r[i],cur);
	}
	if(!F) return 1;
	return 0;
}
void search(){	
	int l = 0,r =1e9+9;
	while(l<=r){
		int mid=(l+r)/2; 
		if(check(mid)) { 
			ans =min(ans, (mid-val[0])); 
			r=mid-1;
		}
		else l=mid+1;
	}
}
 main(){
 	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	// t=1;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin >> a[i][j]; 
			val1.push_back(a[i][j]);
		}
		
	} 
	sort(val1.begin(),val1.end());
	for(int i=0;i<val1.size();i++){
		if(!i || val1[i]!=val1[i-1]) val.push_back(val1[i]);
	}
	 ans=val.back()-val[0];
	search();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m/2;j++){
			swap(a[i][j],a[i][m-j+1]);
		}
	}
	search();
	cout<<ans;
}

Compilation message

joioi.cpp:59:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 |  main(){
      |       ^
joioi.cpp: In function 'int main()':
joioi.cpp:71:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for(int i=0;i<val1.size();i++){
      |              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 12 ms 1576 KB Output is correct
17 Correct 13 ms 1872 KB Output is correct
18 Correct 13 ms 1876 KB Output is correct
19 Correct 14 ms 1876 KB Output is correct
20 Correct 12 ms 1744 KB Output is correct
21 Correct 13 ms 1872 KB Output is correct
22 Correct 12 ms 1960 KB Output is correct
23 Correct 14 ms 1872 KB Output is correct
24 Correct 12 ms 1796 KB Output is correct
25 Correct 16 ms 1968 KB Output is correct
26 Correct 13 ms 1872 KB Output is correct
27 Correct 13 ms 1872 KB Output is correct
28 Correct 12 ms 1872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 12 ms 1576 KB Output is correct
17 Correct 13 ms 1872 KB Output is correct
18 Correct 13 ms 1876 KB Output is correct
19 Correct 14 ms 1876 KB Output is correct
20 Correct 12 ms 1744 KB Output is correct
21 Correct 13 ms 1872 KB Output is correct
22 Correct 12 ms 1960 KB Output is correct
23 Correct 14 ms 1872 KB Output is correct
24 Correct 12 ms 1796 KB Output is correct
25 Correct 16 ms 1968 KB Output is correct
26 Correct 13 ms 1872 KB Output is correct
27 Correct 13 ms 1872 KB Output is correct
28 Correct 12 ms 1872 KB Output is correct
29 Correct 1091 ms 30948 KB Output is correct
30 Correct 1036 ms 31464 KB Output is correct
31 Correct 1218 ms 32608 KB Output is correct
32 Correct 1120 ms 32596 KB Output is correct
33 Correct 955 ms 28532 KB Output is correct
34 Correct 1285 ms 32580 KB Output is correct
35 Correct 1195 ms 68380 KB Output is correct
36 Correct 974 ms 87948 KB Output is correct
37 Correct 1354 ms 95156 KB Output is correct