Submission #540797

# Submission time Handle Problem Language Result Execution time Memory
540797 2022-03-21T18:55:40 Z LucaDantas Land of the Rainbow Gold (APIO17_rainbow) C++17
11 / 100
32 ms 836 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();
}

# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 13 ms 340 KB Output is correct
3 Correct 32 ms 344 KB Output is correct
4 Correct 30 ms 340 KB Output is correct
5 Correct 11 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 24 ms 340 KB Output is correct
12 Correct 21 ms 384 KB Output is correct
13 Correct 15 ms 384 KB Output is correct
14 Correct 8 ms 316 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 596 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 13 ms 340 KB Output is correct
3 Correct 32 ms 344 KB Output is correct
4 Correct 30 ms 340 KB Output is correct
5 Correct 11 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 24 ms 340 KB Output is correct
12 Correct 21 ms 384 KB Output is correct
13 Correct 15 ms 384 KB Output is correct
14 Correct 8 ms 316 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Runtime error 1 ms 836 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 13 ms 340 KB Output is correct
3 Correct 32 ms 344 KB Output is correct
4 Correct 30 ms 340 KB Output is correct
5 Correct 11 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 24 ms 340 KB Output is correct
12 Correct 21 ms 384 KB Output is correct
13 Correct 15 ms 384 KB Output is correct
14 Correct 8 ms 316 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Runtime error 1 ms 836 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -