답안 #1117164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1117164 2024-11-22T21:20:58 Z pedroslrey 무지개나라 (APIO17_rainbow) C++17
11 / 100
3000 ms 1048576 KB
#include "rainbow.h"
#include <bits/stdc++.h>

using namespace std;

vector<vector<bool>> M;

void init(int n, int m, int sx, int sy, int sl, char *serp) {
	M.assign(n, vector<bool>(m));

	--sx; --sy;
	map<char, int> sdx{{'N', -1}, {'S', 1}};
	map<char, int> sdy{{'W', -1}, {'E', 1}};
	M[sx][sy] = true;
	for (int i = 0; i < sl; ++i) {
		char c = serp[i];

		sx += sdx[c]; sy += sdy[c];
		M[sx][sy] = true;
	}

	// int comp = 0;
	// pref.assign(n, vector<int>(m));
	// for (int i = 0; i < n; ++i)
	// 	for (int j = 0; j < m; ++j)
	// 		if (M[i][j] == 0) {
	// 			pref[i][j] = 1;
	// 			pos.emplace_back(i, j);
	// 			dfs(i, j, ++comp);
	// 		}

	// for (int i = 0; i < n; ++i)
	// 	for (int j = 0; j < m; ++j)
	// 		pref[i][j] += (i > 0 ? pref[i-1][j] : 0) 
	// 					+ (j > 0 ? pref[i][j-1] : 0) 
	// 					- (i > 0 && j > 0 ? pref[i-1][j-1] : 0);
}

// int grid_sum(int x1, int y1, int x2, int y2) {
// 	return pref[x2][y2]
// 		   - (x1 > 0 ? pref[x1 - 1][y2] : 0)
// 		   - (y1 > 0 ? pref[x2][y1 - 1] : 0) 
// 		   + (x1 > 0 && y1 > 0 ? pref[x1 - 1][y1 - 1] : 0);
// }

int colour(int x1, int y1, int x2, int y2) {
	--x1; --y1; --x2; --y2;	

	static vector<vector<bool>> marc;
	marc.assign(M.size(), vector<bool>(M[0].size()));

	function<void (int, int)> dfs = [&](int x, int y) {
		marc[x][y] = true;

		static vector<int> dx{1, 0, -1, 0};
		static vector<int> dy{0, 1, 0, -1};

		for (int k = 0; k < 4; ++k) {
			int nx = x + dx[k], ny = y + dy[k];

			if (nx < x1 || nx > x2 || ny < y1 || ny > y2) continue;
			if (M[nx][ny] || marc[nx][ny]) continue;

			dfs(nx, ny);
		}
	};

	int ans = 0;
	for (int i = x1; i <= x2; ++i) 
		for (int j = y1; j <= y2; ++j) 
			if (!M[i][j] && !marc[i][j]) {
				++ans;
				dfs(i, j);
			}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 13 ms 336 KB Output is correct
3 Correct 29 ms 592 KB Output is correct
4 Correct 28 ms 588 KB Output is correct
5 Correct 14 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 21 ms 620 KB Output is correct
12 Correct 19 ms 348 KB Output is correct
13 Correct 20 ms 348 KB Output is correct
14 Correct 12 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Execution timed out 3054 ms 22296 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 799 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 13 ms 336 KB Output is correct
3 Correct 29 ms 592 KB Output is correct
4 Correct 28 ms 588 KB Output is correct
5 Correct 14 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 21 ms 620 KB Output is correct
12 Correct 19 ms 348 KB Output is correct
13 Correct 20 ms 348 KB Output is correct
14 Correct 12 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Execution timed out 3041 ms 9544 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 13 ms 336 KB Output is correct
3 Correct 29 ms 592 KB Output is correct
4 Correct 28 ms 588 KB Output is correct
5 Correct 14 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 21 ms 620 KB Output is correct
12 Correct 19 ms 348 KB Output is correct
13 Correct 20 ms 348 KB Output is correct
14 Correct 12 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Execution timed out 3041 ms 9544 KB Time limit exceeded
19 Halted 0 ms 0 KB -