Submission #41016

# Submission time Handle Problem Language Result Execution time Memory
41016 2018-02-11T13:41:05 Z IvanC The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
2277 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
int matriz[MAXN][MAXN],MinVal,MaxVal,N,M,satisfazem;
void flip1(){
	for(int linha = 1;linha<=N;linha++){
		for(int i = 1,j = M;i <= j;i++,j--){
			swap(matriz[linha][i],matriz[linha][j]);
		}
	}
}
void flip2(){
	for(int coluna = 1;coluna<=M;coluna++){
		for(int i = 1,j = N;i<=j;i++,j--){
			swap(matriz[i][coluna],matriz[j][coluna]);
		}
	}
}
int checa1(int delta){
	int last = M;
	int tot = 0;
	for(int linha = 1;linha<=N;linha++){
		int old = last;
		last = 0;
		for(int coluna = 1;coluna<=old;coluna++){
			if(matriz[linha][coluna] > MinVal + delta) break;
			if(matriz[linha][coluna] < MaxVal - delta) tot++;
			last = coluna;
		}
	}
	return tot;
}
int checa2(int delta){
	int last = N;
	int tot = 0;
	for(int coluna = 1;coluna<=M;coluna++){
		int old = last;
		last = 0;
		for(int linha = 1;linha<=old;linha++){
			if(matriz[linha][coluna] > MinVal + delta) break;
			if(matriz[linha][coluna] < MaxVal - delta) tot++;
			last = linha;
		}
	}
	return tot;
}
int checa(int delta){
	satisfazem = 0;
	for(int i = 1;i<=N;i++){
		for(int j = 1;j<=M;j++){
			if(matriz[i][j] < MaxVal - delta) satisfazem++;
		}
	}
	if(checa1(delta) == satisfazem) return 1;
	flip1();
	if(checa1(delta) == satisfazem) return 1;
	flip2();
	if(checa1(delta) == satisfazem) return 1;
	flip1();
	if(checa1(delta) == satisfazem) return 1;
	if(checa2(delta) == satisfazem) return 1;
	flip1();
	if(checa2(delta) == satisfazem) return 1;
	flip2();
	if(checa2(delta) == satisfazem) return 1;
	flip1();
	if(checa2(delta) == satisfazem) return 1;
	return 0;
}
int main(){
	scanf("%d %d",&N,&M);
	for(int i = 1;i<=N;i++){
		for(int j = 1;j<=M;j++){
			scanf("%d",&matriz[i][j]);
		}
	}
	MinVal = MaxVal = matriz[1][1];
	for(int i = 1;i<=N;i++){
		for(int j = 1;j<=M;j++){
			MinVal = min(MinVal,matriz[i][j]);
			MaxVal = max(MaxVal,matriz[i][j]);
		}
	}
	int ini = 0, fim = MaxVal - MinVal,resp = -1,meio;
	while(ini <= fim){
		meio = (ini+fim)/2;
		if(checa(meio)){
			resp = meio;
			fim = meio - 1;
		}
		else{
			ini = meio + 1;
		}
	}
	printf("%d\n",resp);
	return 0;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:71:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&M);
                      ^
joioi.cpp:74:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&matriz[i][j]);
                             ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 700 KB Output is correct
5 Correct 1 ms 700 KB Output is correct
6 Correct 1 ms 816 KB Output is correct
7 Correct 2 ms 816 KB Output is correct
8 Correct 2 ms 816 KB Output is correct
9 Correct 2 ms 816 KB Output is correct
10 Correct 1 ms 816 KB Output is correct
11 Correct 1 ms 816 KB Output is correct
12 Correct 2 ms 816 KB Output is correct
13 Correct 2 ms 816 KB Output is correct
14 Correct 2 ms 816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 700 KB Output is correct
5 Correct 1 ms 700 KB Output is correct
6 Correct 1 ms 816 KB Output is correct
7 Correct 2 ms 816 KB Output is correct
8 Correct 2 ms 816 KB Output is correct
9 Correct 2 ms 816 KB Output is correct
10 Correct 1 ms 816 KB Output is correct
11 Correct 1 ms 816 KB Output is correct
12 Correct 2 ms 816 KB Output is correct
13 Correct 2 ms 816 KB Output is correct
14 Correct 2 ms 816 KB Output is correct
15 Correct 2 ms 816 KB Output is correct
16 Correct 10 ms 1680 KB Output is correct
17 Correct 15 ms 2024 KB Output is correct
18 Correct 12 ms 2296 KB Output is correct
19 Correct 12 ms 2564 KB Output is correct
20 Correct 12 ms 2724 KB Output is correct
21 Correct 19 ms 3224 KB Output is correct
22 Correct 17 ms 3628 KB Output is correct
23 Correct 17 ms 4012 KB Output is correct
24 Correct 16 ms 4400 KB Output is correct
25 Correct 16 ms 4744 KB Output is correct
26 Correct 19 ms 5148 KB Output is correct
27 Correct 20 ms 5660 KB Output is correct
28 Correct 20 ms 5968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 700 KB Output is correct
5 Correct 1 ms 700 KB Output is correct
6 Correct 1 ms 816 KB Output is correct
7 Correct 2 ms 816 KB Output is correct
8 Correct 2 ms 816 KB Output is correct
9 Correct 2 ms 816 KB Output is correct
10 Correct 1 ms 816 KB Output is correct
11 Correct 1 ms 816 KB Output is correct
12 Correct 2 ms 816 KB Output is correct
13 Correct 2 ms 816 KB Output is correct
14 Correct 2 ms 816 KB Output is correct
15 Correct 2 ms 816 KB Output is correct
16 Correct 10 ms 1680 KB Output is correct
17 Correct 15 ms 2024 KB Output is correct
18 Correct 12 ms 2296 KB Output is correct
19 Correct 12 ms 2564 KB Output is correct
20 Correct 12 ms 2724 KB Output is correct
21 Correct 19 ms 3224 KB Output is correct
22 Correct 17 ms 3628 KB Output is correct
23 Correct 17 ms 4012 KB Output is correct
24 Correct 16 ms 4400 KB Output is correct
25 Correct 16 ms 4744 KB Output is correct
26 Correct 19 ms 5148 KB Output is correct
27 Correct 20 ms 5660 KB Output is correct
28 Correct 20 ms 5968 KB Output is correct
29 Correct 1432 ms 42240 KB Output is correct
30 Correct 1354 ms 64480 KB Output is correct
31 Correct 1528 ms 87528 KB Output is correct
32 Correct 1731 ms 110692 KB Output is correct
33 Correct 1183 ms 128672 KB Output is correct
34 Correct 1542 ms 154004 KB Output is correct
35 Correct 2277 ms 192764 KB Output is correct
36 Correct 1686 ms 226428 KB Output is correct
37 Correct 2247 ms 262144 KB Output is correct