Submission #75823092


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int r(int n, int i, int offset) {
	if (offset < 0) {
		return (i + offset < 0) ? i + offset + n : i + offset;
	}
	else if (offset > 0){
		return (i + offset) % n;
	}
	return i;
}

bool f(vector<int>& v, int i) {
	int pr = r(v.size(), i, -1);
	int ppr = r(v.size(), i, -2);
	int nx = r(v.size(), i, 1);
	int nnx = r(v.size(), i, 2);
	if ((v[pr] == v[ppr]) ||
		(v[pr] == v[nx]) ||
		(v[nx] == v[nnx]))
	{
		return true;
	}
	return false;
}




int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t;
	cin >> t;

	while (t--) {

		int n;
		string s;
		cin >> n >> s;

		vector<int>v(n);
		vector<bool>known(n, false); // 자기거 앎?
		for (int i = 0; i < n; i++) {
			v[i] = (s[i] == 'O') ? 1 : -1;
		}

		vector<int>ans(n, -1);
		int round;

		for (int k = 1; k <= n/2; k++) {
			round = k;
			if (n == 3 && k == 2) break;
			for (int i = 0; i < n; i++) {
				if (known[i] == true) continue;
				vector<int> temp = v;
				temp[i] = -67;
				if (f(temp, i)) { //단독유추가능?
					known[i] = true;
				}
				else {
					if (known[r(n, i, -1)] == true && ans[r(n, i, -1)] != round) { //왼쪽꺼 보고 내꺼 유추 가능한지
						if (v[r(n, r(n, i, -1), -2)] != v[r(n, r(n, i, -1), -1)]) {
							known[i] = true;
						}
					}
					if (known[r(n, i, 1)] == true && ans[r(n, i, 1)] != round) { //오른쪽 보고 ''
						if (v[r(n, r(n, i, 1), 2)] != v[r(n, r(n, i, 1), 1)]) {
							known[i] = true;
						}
					}
					if (known[r(n, i, -2)] == true && ans[r(n, i, -2)] != round) { //왼왼쪽 ''
						if (v[r(n, r(n, i, -2), -2)] != v[r(n, r(n, i, -2), -1)] &&
							v[r(n, r(n, i, -2), -1)] != v[r(n, r(n, i, -2), 1)]) {
							known[i] = true;
						}
					}
					if (known[r(n, i, 2)] == true && ans[r(n, i, 2)] != round) { //오오른쪽 ''
						if (v[r(n, r(n, i, 2), 2)] != v[r(n, r(n, i, 2), 1)] &&
							v[r(n, r(n, i, 2), -1)] != v[r(n, r(n, i, 2), 1)]) {
							known[i] = true;
						}
					}


				}
				if (known[i] == true) ans[i] = round;
			}
		}

		if (n == 3) {
			for (int i = 0; i < n; i++) {
				if (ans[i] == -1) {
					ans[i] = 2;
				}
			}
		}

		for (int i = 0; i < n; i++) {
			cout << ans[i] << " ";
		}
		cout << "\n";





	}



	return 0;
}

Submission Info

Submission Time
Task J - DETOX
User mollusca
Language C++23 (GCC 15.2.0)
Score 0
Code Size 2398 Byte
Status WA
Exec Time > 2000 ms
Memory 4776 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 1
AC × 2
WA × 10
TLE × 14
Set Name Test Cases
Sample 00-sample-001.txt
All 00-sample-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 1 ms 3572 KiB
01-002.txt AC 30 ms 3572 KiB
01-003.txt WA 38 ms 3552 KiB
01-004.txt WA 37 ms 3628 KiB
01-005.txt WA 37 ms 3672 KiB
01-006.txt WA 37 ms 3620 KiB
01-007.txt WA 38 ms 3640 KiB
01-008.txt WA 555 ms 3628 KiB
01-009.txt WA 562 ms 3552 KiB
01-010.txt WA 492 ms 3640 KiB
01-011.txt WA 140 ms 3700 KiB
01-012.txt WA 1137 ms 3768 KiB
01-013.txt TLE > 2000 ms 4240 KiB
01-014.txt TLE > 2000 ms 4460 KiB
01-015.txt TLE > 2000 ms 4692 KiB
01-016.txt TLE > 2000 ms 4648 KiB
01-017.txt TLE > 2000 ms 4744 KiB
01-018.txt TLE > 2000 ms 4648 KiB
01-019.txt TLE > 2000 ms 4720 KiB
01-020.txt TLE > 2000 ms 4700 KiB
01-021.txt TLE > 2000 ms 4776 KiB
01-022.txt TLE > 2000 ms 4676 KiB
01-023.txt TLE > 2000 ms 4688 KiB
01-024.txt TLE > 2000 ms 4720 KiB
01-025.txt TLE > 2000 ms 4676 KiB
01-026.txt TLE > 2000 ms 4716 KiB