This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |