답안 #558967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558967 2022-05-09T04:26:14 Z blue The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
3657 ms 86552 KB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

#define sz(x) int(x.size())
using vi = vector<int>;
using vvi = vector<vi>;

vvi T;

int lim;

//1 = lo, 2 = hi, 3 = both

bool solve()
{
	int H = sz(T) - 2;
	int W = sz(T[0]) - 2;

	bool works = 1;

	vvi P = T;
	for(int i = 1; i <= H; i++)
	{
		for(int j = 1; j <= W; j++)
		{
			P[i][j] = (P[i-1][j] || P[i][j-1] || (T[i][j] == 1));
			if(P[i][j] && (T[i][j] == 2))
				works = 0;
		}
	}

	return works;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int H, W;
	cin >> H >> W;

	int res = 2'000'000'001;

	int amx = 0, amn = 1'000'000'001;

	vvi A = vvi(1+H+1, vi(1+W+1));
	for(int i = 1; i <= H; i++)
	{
		for(int j = 1; j <= W; j++)
		{
			cin >> A[i][j];

			amx = max(amx, A[i][j]);
			amn = min(amn, A[i][j]);
		}
	}

	T = vvi(1+H+1, vi(1+W+1));

	int lo = 0, hi = 1'000'000'000;
	while(lo != hi)
	{
		lim = (lo+hi)/2;

		bool works = 0;

		bool failed = 0;

		for(int i = 1; i <= H; i++)
		{
			for(int j = 1; j <= W; j++)
			{
				int islo = (A[i][j] - amn) <= lim;
				int ishi = (amx - A[i][j]) <= lim;

				if(islo && ishi)
					T[i][j] = 3;
				else if(islo)
					T[i][j] = 1;
				else if(ishi)
					T[i][j] = 2;
				else
					failed = 1;
			}
		}

		if(failed)
		{
			works = 0;
		}
		else
		{
			works = 0;
			works |= solve();

			for(int i = 1; i <= H; i++)
				reverse(T[i].begin(), T[i].end());

			works |= solve();

			for(int j = 1; j <= W; j++)
				for(int i = 1; 2*i <= H; i++)
					swap(T[i][j], T[H-i+1][j]);

			works |= solve();

			for(int i = 1; i <= H; i++)
				reverse(T[i].begin(), T[i].end());

			works |= solve();
		}

		if(works)
			hi = lim;
		else
			lo = lim+1;

	}

	cout << lo << '\n';
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:46:6: warning: unused variable 'res' [-Wunused-variable]
   46 |  int res = 2'000'000'001;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 20 ms 772 KB Output is correct
17 Correct 23 ms 1084 KB Output is correct
18 Correct 16 ms 1088 KB Output is correct
19 Correct 22 ms 1092 KB Output is correct
20 Correct 23 ms 1000 KB Output is correct
21 Correct 22 ms 1208 KB Output is correct
22 Correct 12 ms 1188 KB Output is correct
23 Correct 22 ms 1180 KB Output is correct
24 Correct 12 ms 1108 KB Output is correct
25 Correct 26 ms 1296 KB Output is correct
26 Correct 22 ms 1208 KB Output is correct
27 Correct 22 ms 1208 KB Output is correct
28 Correct 23 ms 1212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 20 ms 772 KB Output is correct
17 Correct 23 ms 1084 KB Output is correct
18 Correct 16 ms 1088 KB Output is correct
19 Correct 22 ms 1092 KB Output is correct
20 Correct 23 ms 1000 KB Output is correct
21 Correct 22 ms 1208 KB Output is correct
22 Correct 12 ms 1188 KB Output is correct
23 Correct 22 ms 1180 KB Output is correct
24 Correct 12 ms 1108 KB Output is correct
25 Correct 26 ms 1296 KB Output is correct
26 Correct 22 ms 1208 KB Output is correct
27 Correct 22 ms 1208 KB Output is correct
28 Correct 23 ms 1212 KB Output is correct
29 Correct 3035 ms 67480 KB Output is correct
30 Correct 3012 ms 65816 KB Output is correct
31 Correct 3352 ms 70796 KB Output is correct
32 Correct 3140 ms 70880 KB Output is correct
33 Correct 1962 ms 61784 KB Output is correct
34 Correct 3290 ms 70792 KB Output is correct
35 Correct 3360 ms 86384 KB Output is correct
36 Correct 1728 ms 75548 KB Output is correct
37 Correct 3657 ms 86552 KB Output is correct