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 <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
const int MAXN = 500100, MAXK = 60;
const ll MOD = 1e9+7;
const int INF = 1e8;
const ld PI = asin(1) * 2;
void setIO () {
FAST_IO;
}
void setIO (string s) {
setIO();
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
int n;
deque<pair<int, pii>> q;
vector<pair<pii, int>> ans;
int main() {
setIO();
cin >> n;
FOR(i, 1, n) {
int next = i+1;
if (next > n) next = 1;
char c; cin >> c;
q.push_back({(c-'0'), {i, next}});
}
while (q.size() > 3) {
auto cur = q.front();
q.pop_front();
if (q.front().f != cur.f) {
int c = 1;
FOR(i, 1, 3) {
if (i != q.front().f && i != cur.f) c = i;
}
ans.pb({{cur.s.f, q.front().s.s}, c});
q.pop_front();
q.push_front({c, {cur.s.f, q.front().s.s}});
} else if (q.back().f != cur.f) {
int c = 1;
FOR(i, 1, 3) {
if (i != q.front().f && i != cur.f) c = i;
}
ans.pb({{q.back().s.f, cur.s.s}, c});
q.pop_back();
q.push_back({c, {q.back().s.f, cur.s.s}});
} else {
cout << "NE";
return 0;
}
}
vi cols;
while (!q.empty()) {cols.pb(q.front().f); q.pop_front();}
FOR(i, 0, (int)cols.size()-1) {
if (cols[i] == cols[(i+1)%((int)cols.size())]) {
cout << "NE";
return 0;
}
}
cout << "DA\n";
for (auto p : ans) cout << p.f.f << " " << p.f.s << " " << p.s << endl;
return 0;
}
Compilation message (stderr)
trobojnica.cpp: In function 'void setIO(std::__cxx11::string)':
trobojnica.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen((s+".in").c_str(),"r",stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
trobojnica.cpp:32:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen((s+".out").c_str(),"w",stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |