답안 #540798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540798 2022-03-21T18:56:00 Z LucaDantas 무지개나라 (APIO17_rainbow) C++17
11 / 100
32 ms 596 KB
#include <bits/stdc++.h>
#include "rainbow.h"
using namespace std;

constexpr int maxn = 55*55, lado = 55;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

struct DSU {
	int pai[maxn], peso[maxn];
	void init() { for(int i = 0; i < maxn; i++) pai[i] = i, peso[i] = 1; }
	int find(int x) { return pai[x] == x ? x : pai[x] = find(pai[x]); }
	void join(int a, int b) {
		a = find(a), b = find(b);
		if(a == b) return;
		if(peso[a] < peso[b])
			swap(a, b);
		pai[b] = a;
		peso[a] += peso[b];
	}
} dsu;

bool mark[lado][lado];

void dfs(int x, int y, int here, int moves, char *S) {
	mark[x][y] = 1;
	if(here == moves) return;
	char c = S[here];
	if(c == 'N') dfs(x-1, y, here+1, moves, S);
	else if(c == 'S') dfs(x+1, y, here+1, moves, S);
	else if(c == 'W') dfs(x, y-1, here+1, moves, S);
	else if(c == 'E') dfs(x, y+1, here+1, moves, S);
}

void init(int R, int C, int sr, int sc, int M, char *S) {
	if(max(R, C) > 50) assert(0);
	dfs(sr, sc, 0, M, S);
}

int get(int a, int b) { return a * (52) + b; }

int colour(int ar, int ac, int br, int bc) {
	dsu.init();
	for(int r = ar; r <= br; r++) {
		for(int c = ac; c <= bc; c++) {
			if(mark[r][c]) continue;
			for(int k = 0; k < 4; k++)
				if(!mark[r+dx[k]][c+dy[k]])
					dsu.join(get(r,c), get(r + dx[k], c + dy[k]));
		}
	}
	static vector<int> siuu; siuu.clear();
	for(int r = ar; r <= br; r++)
		for(int c = ac; c <= bc; c++)
			if(!mark[r][c])
				siuu.push_back(dsu.find(get(r, c)));
	sort(siuu.begin(), siuu.end());
	return unique(siuu.begin(), siuu.end()) - siuu.begin();
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 13 ms 340 KB Output is correct
3 Correct 30 ms 360 KB Output is correct
4 Correct 32 ms 340 KB Output is correct
5 Correct 12 ms 340 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 27 ms 348 KB Output is correct
12 Correct 25 ms 340 KB Output is correct
13 Correct 18 ms 348 KB Output is correct
14 Correct 7 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 596 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 13 ms 340 KB Output is correct
3 Correct 30 ms 360 KB Output is correct
4 Correct 32 ms 340 KB Output is correct
5 Correct 12 ms 340 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 27 ms 348 KB Output is correct
12 Correct 25 ms 340 KB Output is correct
13 Correct 18 ms 348 KB Output is correct
14 Correct 7 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Runtime error 1 ms 596 KB Execution killed with signal 6
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 13 ms 340 KB Output is correct
3 Correct 30 ms 360 KB Output is correct
4 Correct 32 ms 340 KB Output is correct
5 Correct 12 ms 340 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 27 ms 348 KB Output is correct
12 Correct 25 ms 340 KB Output is correct
13 Correct 18 ms 348 KB Output is correct
14 Correct 7 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Runtime error 1 ms 596 KB Execution killed with signal 6
19 Halted 0 ms 0 KB -