답안 #378251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378251 2021-03-16T10:29:31 Z peijar The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
594 ms 101884 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2000;
const int MAXROT = 4;

int altitude[MAXROT][MAXN][MAXN];
int nbLig, nbCol;
int petit(1e9), grand(0);

bool isOk(int iRot, int deltaMax)
{
	int prv(nbCol-1);
	for (int iLig(0); iLig < nbLig; ++iLig)
	{
		int curCol(-1);
		while (curCol + 1 <= prv and altitude[iRot][iLig][curCol+1] <= petit + deltaMax)
			++curCol;
		prv = curCol;
		if (prv == -1 and !iLig)
			return false;
		for (int iCol=curCol+1; iCol < nbCol; ++iCol)
			if (altitude[iRot][iLig][iCol] < grand - deltaMax)
				return false;
	}
	return true;
}

bool can(int delta)
{
	for (int iRot = 0; iRot < MAXROT; ++iRot) 
		if (isOk(iRot, delta))
			return true;
	return false;
}

signed main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> nbLig >> nbCol;
	for (int iLig = 0; iLig < nbLig; ++iLig) 
		for (int iCol = 0; iCol < nbCol; ++iCol) 
			cin >> altitude[0][iLig][iCol];
	for (int iLig = 0; iLig < nbLig; ++iLig) 
		for (int iCol = 0; iCol < nbCol; ++iCol) 
		{
			altitude[1][iLig][iCol] = altitude[0][iLig][nbCol - iCol-1];
			altitude[2][iLig][iCol] = altitude[0][nbLig-iLig-1][iCol];
			altitude[3][iLig][iCol] = altitude[0][nbLig-iLig-1][nbCol-iCol-1];
		}
	for (int iLig = 0; iLig < nbLig; ++iLig) 
		for (int iCol = 0; iCol < nbCol; ++iCol) 
			petit = min(petit, altitude[0][iLig][iCol]),
						grand = max(grand, altitude[0][iLig][iCol]);
	int lo(0), up(1e9);
	while (lo < up)
	{
		int mid = (lo + up)/2;
		if (can(mid))
			up = mid;
		else
			lo = mid + 1;
	}
	cout << lo << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
16 Correct 7 ms 4204 KB Output is correct
17 Correct 10 ms 4460 KB Output is correct
18 Correct 7 ms 4460 KB Output is correct
19 Correct 7 ms 4460 KB Output is correct
20 Correct 6 ms 3948 KB Output is correct
21 Correct 11 ms 4588 KB Output is correct
22 Correct 10 ms 4736 KB Output is correct
23 Correct 8 ms 4588 KB Output is correct
24 Correct 9 ms 4076 KB Output is correct
25 Correct 8 ms 4588 KB Output is correct
26 Correct 8 ms 4736 KB Output is correct
27 Correct 9 ms 4608 KB Output is correct
28 Correct 11 ms 4736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
16 Correct 7 ms 4204 KB Output is correct
17 Correct 10 ms 4460 KB Output is correct
18 Correct 7 ms 4460 KB Output is correct
19 Correct 7 ms 4460 KB Output is correct
20 Correct 6 ms 3948 KB Output is correct
21 Correct 11 ms 4588 KB Output is correct
22 Correct 10 ms 4736 KB Output is correct
23 Correct 8 ms 4588 KB Output is correct
24 Correct 9 ms 4076 KB Output is correct
25 Correct 8 ms 4588 KB Output is correct
26 Correct 8 ms 4736 KB Output is correct
27 Correct 9 ms 4608 KB Output is correct
28 Correct 11 ms 4736 KB Output is correct
29 Correct 429 ms 81984 KB Output is correct
30 Correct 417 ms 84492 KB Output is correct
31 Correct 512 ms 86124 KB Output is correct
32 Correct 449 ms 86112 KB Output is correct
33 Correct 393 ms 75400 KB Output is correct
34 Correct 450 ms 86252 KB Output is correct
35 Correct 543 ms 101820 KB Output is correct
36 Correct 508 ms 96624 KB Output is correct
37 Correct 594 ms 101884 KB Output is correct