Submission #124556

#TimeUsernameProblemLanguageResultExecution timeMemory
124556wilwxkThe Kingdom of JOIOI (JOI17_joioi)C++14
100 / 100
928 ms70628 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAXN=2e3+5;
int v[3][MAXN][MAXN];
int n, m, maior, menor;

bool testa(int val, int k) {
	vector<pair<int, int> > inter;
	for(int i=1; i<=n; i++) {
		int a=m+1, b=0;
		while(a-1>=1&&v[k][i][a-1]>=maior-val) a--;
		while(b+1<=m&&v[k][i][b+1]<=menor+val) b++;
		a--; if(a>b) return 0; 
		inter.push_back({a, b});
	}
	bool ok=1, ok2=1;
	int ult=0, ult2=m+1;
	for(auto cur : inter) {
		if(cur.second<ult) ok=0;
		if(cur.first>ult2) ok2=0;
		ult=max(ult, cur.first);
		ult2=min(ult2, cur.second);
	}
	return (ok||ok2);
}

bool testa2(int k) {
	return (testa(k, 1)||testa(k, 2));
}

int main() {
	scanf("%d %d", &n, &m);
	maior=-1; menor=1e9+9;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			scanf("%d", &v[1][i][j]);
			v[2][i][m-j+1]=v[1][i][j];
			maior=max(maior, v[1][i][j]);
			menor=min(menor, v[1][i][j]);
		}
	}

	int respf=0;
	// testa(11, 1);
	for(int i=maior; i>0; i/=2) while(respf+i<=maior&&!testa2(respf+i)) respf+=i;

	printf("%d\n", respf+1);
}

Compilation message (stderr)

joioi.cpp: In function 'int main()':
joioi.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
joioi.cpp:37:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &v[1][i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...