답안 #558966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558966 2022-05-09T04:24:25 Z blue The Kingdom of JOIOI (JOI17_joioi) C++17
15 / 100
4000 ms 596 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;

	for(int i1 = 1; i1 <= H; i1++)
		for(int j1 = 1; j1 <= W; j1++)
			for(int i2 = 1; i2 <= H; i2++)
				for(int j2 = 1; j2 <= W; j2++)
					if(T[i1][j1] == 1)
						if(T[i2][j2] == 2)
							if(i1 <= i2 && j1 <= j2)
								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:44:6: warning: unused variable 'res' [-Wunused-variable]
   44 |  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 324 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 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 324 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 315 ms 340 KB Output is correct
16 Execution timed out 4061 ms 596 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 324 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 315 ms 340 KB Output is correct
16 Execution timed out 4061 ms 596 KB Time limit exceeded
17 Halted 0 ms 0 KB -