Submission #124556

# Submission time Handle Problem Language Result Execution time Memory
124556 2019-07-03T13:47:19 Z wilwxk The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
928 ms 70628 KB
#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

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 time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 7 ms 2296 KB Output is correct
17 Correct 11 ms 2424 KB Output is correct
18 Correct 10 ms 2552 KB Output is correct
19 Correct 11 ms 2456 KB Output is correct
20 Correct 10 ms 2296 KB Output is correct
21 Correct 17 ms 2652 KB Output is correct
22 Correct 12 ms 2552 KB Output is correct
23 Correct 12 ms 2680 KB Output is correct
24 Correct 11 ms 2424 KB Output is correct
25 Correct 12 ms 2552 KB Output is correct
26 Correct 13 ms 2680 KB Output is correct
27 Correct 14 ms 2680 KB Output is correct
28 Correct 15 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 7 ms 2296 KB Output is correct
17 Correct 11 ms 2424 KB Output is correct
18 Correct 10 ms 2552 KB Output is correct
19 Correct 11 ms 2456 KB Output is correct
20 Correct 10 ms 2296 KB Output is correct
21 Correct 17 ms 2652 KB Output is correct
22 Correct 12 ms 2552 KB Output is correct
23 Correct 12 ms 2680 KB Output is correct
24 Correct 11 ms 2424 KB Output is correct
25 Correct 12 ms 2552 KB Output is correct
26 Correct 13 ms 2680 KB Output is correct
27 Correct 14 ms 2680 KB Output is correct
28 Correct 15 ms 2680 KB Output is correct
29 Correct 631 ms 52320 KB Output is correct
30 Correct 657 ms 53300 KB Output is correct
31 Correct 643 ms 55056 KB Output is correct
32 Correct 665 ms 54824 KB Output is correct
33 Correct 576 ms 48080 KB Output is correct
34 Correct 657 ms 55160 KB Output is correct
35 Correct 928 ms 70628 KB Output is correct
36 Correct 756 ms 65320 KB Output is correct
37 Correct 880 ms 70620 KB Output is correct