Submission #725261

#TimeUsernameProblemLanguageResultExecution timeMemory
725261SanguineChameleonMars (APIO22_mars)C++17
21 / 100
81 ms3204 KiB
#include "mars.h"
#include <bits/stdc++.h>
using namespace std;

string process(vector<vector<string>> a, int i, int j, int k, int n) {
	if (k == n - 1) {
		int sz = n * 2 + 1;
		vector<vector<int>> grid(sz, vector<int>(sz, -1));
		vector<vector<bool>> flag(sz, vector<bool>(sz, false));
		const vector<int> dx = {1, -1, 0, 0};
		const vector<int> dy = {0, 0, 1, -1};
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				grid[i][j] = a[i][j][0] - '0';
			}
		}
		for (int x = 0; x < 3; x++) {
			for (int y = 0; y < 3; y++) {
				if ((x == 2 || y == 2) && (x != 0) && (y != 0)) {
					for (int i = 0; i < k * 2 + 1; i++) {
						grid[x + i][y + i] = a[x][y][i] - '0';
					}
				}
			}
		}
		for (int x = 0; x < 3; x++) {
			for (int y = 0; y < 3; y++) {
				if ((x == 2 || y == 2) && (x == 0 || y == 0)) {
					int pt = 0;
					int cx = x;
					int cy = y;
					for (int i = k * 2 + 1; i >= 1; i--) {
						for (int j = 0; j < i; j++) {
							grid[cx + j][cy + j] = a[x][y][pt++] - '0';
						}
						if (x == 0) {
							cy++;
						}
						if (y == 0) {
							cx++;
						}
					}
				}
			}
		}
		int cnt = 0;
		for (int i = 0; i < sz; i++) {
			for (int j = 0; j < sz; j++) {
				if (!flag[i][j] && grid[i][j]) {
					cnt++;
					flag[i][j] = true;
					deque<pair<int, int>> q = {{i, j}};
					while (!q.empty()) {
						int cx = q.front().first;
						int cy = q.front().second;
						q.pop_front();
						for (int d = 0; d < 4; d++) {
							int nx = cx + dx[d];
							int ny = cy + dy[d];
							if (0 <= nx && nx < sz && 0 <= ny && ny < sz && grid[nx][ny] && !flag[nx][ny]) {
								flag[nx][ny] = true;
								q.push_back({nx, ny});
							}
						}
					}
				}
			}
		}
		string res;
		while (cnt) {
			res += (char)('0' + (cnt & 1));
			cnt >>= 1;
		}
		res.resize(100, '0');
		return res;
	}
	string res = a[0][0].substr(0, 1);
	if (i == 2 * (n - k - 1) || j == 2 * (n - k - 1)) {
		res += a[1][1].substr(0, 1);
		res += a[2][2].substr(0, k * 2 + 1);
		if (j == 0) {
			res += a[1][0].substr(0, 1);
			res += a[2][1].substr(0, k * 2 + 1);
			res += a[2][0].substr(0, (k * 2 + 1) * (k * 2 + 2) / 2);
		}
		if (i == 0) {
			res += a[0][1].substr(0, 1);
			res += a[1][2].substr(0, k * 2 + 1);
			res += a[0][2].substr(0, (k * 2 + 1) * (k * 2 + 2) / 2);
		}
	}
	res.resize(100, '0');
	return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...