#include <iostream>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <ctime>
#include <set>
#include <algorithm>
#include <iomanip>
#define ll long long
using namespace std;
int get (char c) {
return c - '0';
}
int main() {
//vector<pair<int,int>> vec;
int N;
cin >> N;
string s;
cin >> s;
int val[N];
int pref[N + 1];
pref[0] = 0;
vector<int> oc = {0, 0, 0, 0};
for (int i = 0; i < N; i++) {
pref[i + 1] = pref[i] ^ get(s[i]);
val[i] = get(s[i]);
oc[val[i]]++;
}
vector<pair<int,pair<int,int>>> v;
vector<pair<int,pair<int,int>>> ans;
for (int i = 0; i < N; i++) {
v.push_back(make_pair(val[i], make_pair(i, (i + 1) %N)));
while (v.size() >= 2) {
int n = v.size();
if (v[n - 1].first != v[n - 2].first and !(oc[v[n - 1].first] == 1 and oc[v[n - 2].first] == 1)) {
auto v1 = v[n - 1], v2 = v[n - 2];
int new_col = 6 - v1.first - v2.first;
oc[new_col]++;
oc[v1.first]--;
oc[v2.first]--;
v.pop_back();
v.pop_back();
v.push_back(make_pair(new_col, make_pair(v2.second.first, v1.second.second)));
ans.push_back(v.back());
//assert(ans.back().second.first == ans.back().second.first);
//cout << ans.back().first << " " << ans.back().second << endl;
} else {
break;
}
}
}
if (v.size() == 3 and v[0].first != v[1].first and v[0].first != v[2].first and v[1].first != v[2].first) {
cout << "DA\n";
for (auto& p: ans) {
cout << p.second.first + 1 << " " << p.second.second + 1 << " " << p.first << endl;
}
} else {
cout << "NE\n";
}
//cout << v.size() << endl;
}
//(1, 2)
//(3, 3)
//(2, 2)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
244 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
244 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
300 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
244 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
300 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
243 ms |
8420 KB |
Output is correct |
22 |
Correct |
242 ms |
6808 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
241 ms |
7124 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
119 ms |
3720 KB |
Output is correct |
28 |
Correct |
11 ms |
5440 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
7 ms |
5464 KB |
Output is correct |