답안 #132733

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132733 2019-07-19T12:04:34 Z abra_stone 문명 (KOI17_civilization) C++14
19 / 100
304 ms 22296 KB
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#define N 2005
#define K 100005
using namespace std;

int n, k, ans, ca[K], g[N][N], c[N][N];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
queue<int> qx, qy, qg, qc;

int uni(int p) {
	if (ca[p] == p) return p;
	return ca[p] = uni(ca[p]);
}

void f(int x, int y, int fg, int fc) {
	int t1, t2;
	if (g[x][y] == -1) return;
	if (g[x][y] == 0) {
		qx.push(x);
		qy.push(y);
		qg.push(fg);
		qc.push(fc + 1);
		g[x][y] = fg;
		c[x][y] = fc + 1;
		return;
	}
	t1 = uni(g[x][y]);
	t2 = uni(fg);
	if (t1 != t2) {
		ca[t2] = t1;
		ans = max(ans, max(c[x][y], fc));
		k--;
		if (k == 1) {
			cout << ans << endl;
			exit(0);
		}
	}
}

int main()
{
	int i, j, fx, fy, fg, fc;
	cin >> n >> k;
	if (k == 1) {cout << '0' << endl; return 0;}
	for (i = 1; i <= k; i++) ca[i] = i;
	for (i = 0; i <= n + 1; i++) for (j = 0; j <= n + 1; j++) g[i][j] = -1;
	for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) g[i][j] = 0;
	for (i = 1; i <= k; i++) {
		scanf("%d %d", &fx, &fy);
		qx.push(fx);
		qy.push(fy);
		qg.push(i);
		qc.push(0);
		g[fx][fy] = i;
	}
	while (!qx.empty()) {
		fx = qx.front(), qx.pop();
		fy = qy.front(), qy.pop();
		fg = qg.front(), qg.pop();
		fc = qc.front(), qc.pop();
		for (i = 0; i < 4; i++) {
			f(fx + dx[i], fy + dy[i], fg, fc);
		}
	}
    return 0;
}

Compilation message

civilization.cpp: In function 'int main()':
civilization.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &fx, &fy);
   ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1276 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1272 KB Output is correct
8 Correct 3 ms 1272 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 1272 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1276 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1272 KB Output is correct
8 Correct 3 ms 1272 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 1272 KB Output is correct
12 Correct 87 ms 15920 KB Output is correct
13 Correct 64 ms 15184 KB Output is correct
14 Correct 76 ms 15608 KB Output is correct
15 Correct 64 ms 14456 KB Output is correct
16 Correct 16 ms 10160 KB Output is correct
17 Incorrect 304 ms 22296 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1276 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1272 KB Output is correct
8 Correct 3 ms 1272 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 1272 KB Output is correct
12 Correct 87 ms 15920 KB Output is correct
13 Correct 64 ms 15184 KB Output is correct
14 Correct 76 ms 15608 KB Output is correct
15 Correct 64 ms 14456 KB Output is correct
16 Correct 16 ms 10160 KB Output is correct
17 Incorrect 304 ms 22296 KB Output isn't correct
18 Halted 0 ms 0 KB -