답안 #132726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132726 2019-07-19T11:56:22 Z abra_stone 문명 (KOI17_civilization) C++14
19 / 100
277 ms 22992 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;
	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:52: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 1272 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1272 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1264 KB Output is correct
8 Correct 3 ms 1272 KB Output is correct
9 Correct 3 ms 1276 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1272 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1264 KB Output is correct
8 Correct 3 ms 1272 KB Output is correct
9 Correct 3 ms 1276 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 85 ms 15992 KB Output is correct
13 Correct 63 ms 15224 KB Output is correct
14 Correct 75 ms 15576 KB Output is correct
15 Correct 63 ms 14456 KB Output is correct
16 Correct 15 ms 10076 KB Output is correct
17 Incorrect 277 ms 22992 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1272 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1264 KB Output is correct
8 Correct 3 ms 1272 KB Output is correct
9 Correct 3 ms 1276 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 85 ms 15992 KB Output is correct
13 Correct 63 ms 15224 KB Output is correct
14 Correct 75 ms 15576 KB Output is correct
15 Correct 63 ms 14456 KB Output is correct
16 Correct 15 ms 10076 KB Output is correct
17 Incorrect 277 ms 22992 KB Output isn't correct
18 Halted 0 ms 0 KB -