답안 #50712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50712 2018-06-13T03:59:50 Z MatheusLealV The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
3460 ms 95144 KB
#include <bits/stdc++.h>
#define N 2002
using namespace std;

struct ponto {
	int x, y, val;
};

vector < ponto > P;

inline bool op(ponto a, ponto b){
	return a.val < b.val;
}

int n, m, mat[N][N], A[N][N], B[N][N];

inline int rightmost(int val)
{
	int ini = 0, fim = P.size() - 1, mid, best;

	while(fim >= ini)
	{
		mid = (ini + fim)/2;

		if(P[mid].val - P[0].val <= val) ini = mid + 1, best = mid;

		else fim = mid - 1;
	}

	return best;
}

inline int leftmost(int val)
{
	int ini = 0, fim = P.size() - 1, mid, best;

	while(fim >= ini)
	{
		mid = (ini + fim)/2;

		if(P.back().val - P[mid].val <= val) fim = mid - 1, best = mid;

		else ini = mid + 1;
	}

	return best;
}

inline bool check1()
{
	bool E = 1, D = 1;

	int maior = 0;

	for(int i = n; i >= 1; i--)
	{
		for(int j = 1; j <= m; j++)
			if(A[i][j]) maior = max(maior, j);

		for(int j = 1; j <= maior; j++)
			if(B[i][j]) E = 0;
	}

	maior = 0;

	for(int i = n; i >= 1; i--)
	{
		for(int j = 1; j <= m; j++)
			if(B[i][j]) maior = max(maior, j);

		for(int j = 1; j <= maior; j++)
			if(A[i][j]) D = 0;
	}

	return (E || D);
}

inline bool check2()
{
	int maior = 0, E = 1, D = 1;

	for(int i = 1; i <= n; i ++)
	{
		for(int j = 1; j <= m; j++)
			if(A[i][j]) maior = max(maior, j);

		for(int j = 1; j <= maior; j++)
			if(B[i][j]) E = 0;
	}

	maior = 0;

	for(int i = 1; i <= n; i ++)
	{
		for(int j = 1; j <= m; j++)
			if(B[i][j]) maior = max(maior, j);

		for(int j = 1; j <= maior; j++)
			if(A[i][j]) D = 0;
	}

	return (E || D);
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n>>m;

	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin>>mat[i][j], P.push_back({i, j, mat[i][j]});

	sort(P.begin(), P.end(), op);

	int ini = 0, fim = 1e9, mid, best = -1;

	while(fim >= ini)
	{
		mid = (ini + fim)/2;

		int L = leftmost(mid), R = rightmost(mid);

		memset(A, 0, sizeof A), memset(B, 0, sizeof B);

		if(L <= R || R == L - 1)
		{
			if(R == L - 1) swap(L, R);

			for(int i = 0; i < L; i++)
			{
				int x = P[i].x, y = P[i].y;

				A[x][y] ++;
			}

			for(int i = R + 1; i < P.size(); i++)
			{
				int x = P[i].x, y = P[i].y;

				B[x][y] ++;
			}

			if(check1() || check2())
			{
				best = mid;

				fim = mid - 1;
			}

			else ini = mid + 1;
		}

		else ini = mid + 1;
	}

	cout<<best<<"\n";
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:138:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = R + 1; i < P.size(); i++)
                       ~~^~~~~~~~~~
joioi.cpp:35:40: warning: 'best' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int ini = 0, fim = P.size() - 1, mid, best;
                                        ^~~~
joioi.cpp:129:4: warning: 'best' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if(R == L - 1) swap(L, R);
    ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 31736 KB Output is correct
2 Correct 231 ms 31848 KB Output is correct
3 Correct 220 ms 31916 KB Output is correct
4 Correct 230 ms 31916 KB Output is correct
5 Correct 231 ms 31916 KB Output is correct
6 Correct 220 ms 31916 KB Output is correct
7 Correct 219 ms 31988 KB Output is correct
8 Correct 231 ms 31988 KB Output is correct
9 Correct 228 ms 31988 KB Output is correct
10 Correct 220 ms 31988 KB Output is correct
11 Correct 223 ms 31988 KB Output is correct
12 Correct 228 ms 32068 KB Output is correct
13 Correct 226 ms 32068 KB Output is correct
14 Correct 234 ms 32068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 31736 KB Output is correct
2 Correct 231 ms 31848 KB Output is correct
3 Correct 220 ms 31916 KB Output is correct
4 Correct 230 ms 31916 KB Output is correct
5 Correct 231 ms 31916 KB Output is correct
6 Correct 220 ms 31916 KB Output is correct
7 Correct 219 ms 31988 KB Output is correct
8 Correct 231 ms 31988 KB Output is correct
9 Correct 228 ms 31988 KB Output is correct
10 Correct 220 ms 31988 KB Output is correct
11 Correct 223 ms 31988 KB Output is correct
12 Correct 228 ms 32068 KB Output is correct
13 Correct 226 ms 32068 KB Output is correct
14 Correct 234 ms 32068 KB Output is correct
15 Correct 240 ms 32160 KB Output is correct
16 Correct 231 ms 33428 KB Output is correct
17 Correct 254 ms 33504 KB Output is correct
18 Correct 251 ms 33504 KB Output is correct
19 Correct 249 ms 33504 KB Output is correct
20 Correct 249 ms 33504 KB Output is correct
21 Correct 258 ms 33504 KB Output is correct
22 Correct 248 ms 33504 KB Output is correct
23 Correct 261 ms 33508 KB Output is correct
24 Correct 259 ms 33508 KB Output is correct
25 Correct 274 ms 33508 KB Output is correct
26 Correct 259 ms 33524 KB Output is correct
27 Correct 259 ms 33524 KB Output is correct
28 Correct 284 ms 33524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 31736 KB Output is correct
2 Correct 231 ms 31848 KB Output is correct
3 Correct 220 ms 31916 KB Output is correct
4 Correct 230 ms 31916 KB Output is correct
5 Correct 231 ms 31916 KB Output is correct
6 Correct 220 ms 31916 KB Output is correct
7 Correct 219 ms 31988 KB Output is correct
8 Correct 231 ms 31988 KB Output is correct
9 Correct 228 ms 31988 KB Output is correct
10 Correct 220 ms 31988 KB Output is correct
11 Correct 223 ms 31988 KB Output is correct
12 Correct 228 ms 32068 KB Output is correct
13 Correct 226 ms 32068 KB Output is correct
14 Correct 234 ms 32068 KB Output is correct
15 Correct 240 ms 32160 KB Output is correct
16 Correct 231 ms 33428 KB Output is correct
17 Correct 254 ms 33504 KB Output is correct
18 Correct 251 ms 33504 KB Output is correct
19 Correct 249 ms 33504 KB Output is correct
20 Correct 249 ms 33504 KB Output is correct
21 Correct 258 ms 33504 KB Output is correct
22 Correct 248 ms 33504 KB Output is correct
23 Correct 261 ms 33508 KB Output is correct
24 Correct 259 ms 33508 KB Output is correct
25 Correct 274 ms 33508 KB Output is correct
26 Correct 259 ms 33524 KB Output is correct
27 Correct 259 ms 33524 KB Output is correct
28 Correct 284 ms 33524 KB Output is correct
29 Correct 2549 ms 91744 KB Output is correct
30 Correct 2598 ms 91744 KB Output is correct
31 Correct 3116 ms 94680 KB Output is correct
32 Correct 2084 ms 95144 KB Output is correct
33 Correct 1676 ms 95144 KB Output is correct
34 Correct 2551 ms 95144 KB Output is correct
35 Correct 2780 ms 95144 KB Output is correct
36 Correct 2535 ms 95144 KB Output is correct
37 Correct 3460 ms 95144 KB Output is correct