Submission #75816032
Source Code Expand
#include <bits/stdc++.h>
#define fastio cin.tie(0)->sync_with_stdio(0)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;
int main() {
fastio; int T; cin >> T;
for (int tc = 0; tc < T; tc++) {
int N; string S; cin >> N >> S;
vector<int> ans(N);
queue<pair<int,int>> q;
for (int i = 0; i < N; i++) {
if (S[(i-1+N)%N] == S[(i+1)%N] || S[(i-2+N)%N] == S[(i-1+N)%N] || S[(i+1)%N] == S[(i+2)%N]) {
q.push({ i, 1 }); ans[i] = 1;
}
}
while (!q.empty()) {
auto [i, t] = q.front(); q.pop();
if (!ans[(i-1+N)%N]) {
ans[(i-1+N)%N] = t+1;
q.push({ (i-1+N)%N, t+1 });
}
if (!ans[(i+1)%N]) {
ans[(i+1)%N] = t+1;
q.push({ (i+1)%N, t+1 });
}
}
for (int i = 0; i < N; i++) cout << (ans[i] == 0 ? -1 : ans[i]) << " ";
cout << "\n";
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | J - DETOX |
| User | Lov34ever |
| Language | C++23 (GCC 15.2.0) |
| Score | 100 |
| Code Size | 1181 Byte |
| Status | AC |
| Exec Time | 24 ms |
| Memory | 4712 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 100 / 100 | ||||
| Status |
|
|
| 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 | 24 ms | 3540 KiB |
| 01-003.txt | AC | 18 ms | 3368 KiB |
| 01-004.txt | AC | 18 ms | 3396 KiB |
| 01-005.txt | AC | 18 ms | 3424 KiB |
| 01-006.txt | AC | 18 ms | 3524 KiB |
| 01-007.txt | AC | 18 ms | 3696 KiB |
| 01-008.txt | AC | 18 ms | 3700 KiB |
| 01-009.txt | AC | 18 ms | 3600 KiB |
| 01-010.txt | AC | 18 ms | 3552 KiB |
| 01-011.txt | AC | 17 ms | 3604 KiB |
| 01-012.txt | AC | 18 ms | 3600 KiB |
| 01-013.txt | AC | 18 ms | 4256 KiB |
| 01-014.txt | AC | 19 ms | 4432 KiB |
| 01-015.txt | AC | 18 ms | 4364 KiB |
| 01-016.txt | AC | 18 ms | 4712 KiB |
| 01-017.txt | AC | 18 ms | 4636 KiB |
| 01-018.txt | AC | 18 ms | 4572 KiB |
| 01-019.txt | AC | 18 ms | 4588 KiB |
| 01-020.txt | AC | 18 ms | 4612 KiB |
| 01-021.txt | AC | 18 ms | 4684 KiB |
| 01-022.txt | AC | 19 ms | 4592 KiB |
| 01-023.txt | AC | 18 ms | 4656 KiB |
| 01-024.txt | AC | 18 ms | 4692 KiB |
| 01-025.txt | AC | 18 ms | 4664 KiB |
| 01-026.txt | AC | 20 ms | 4692 KiB |