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 inf 0x3F3F3F3F3F3F3F3F
const int MXN = 20 + 5;
const int mod = 1e9 + 7;
const int LOG = 20;
int n;
vector<array<int, 3>> res;
int ok(vector<array<int, 3>> v)
{
if (v.size() == 3)
{
return v[0][0] != v[1][0] && v[0][0] != v[2][0] && v[1][0] != v[2][0];
}
vector<array<int, 3>> org = v;
if (v[0][0] != v[1][0])
{
int x = 6 - v[0][0] - v[1][0];
array<int, 3> A = v[0], B = v[1];
v.erase(v.begin());
v.erase(v.begin());
v.insert(v.begin(), {x, A[1], B[2]});
if (ok(v))
{
res.push_back({A[1], B[2], x});
return 1;
}
}
v = org;
if (v[1][0] != v[2][0])
{
int x = 6 - v[1][0] - v[2][0];
array<int, 3> A = v[1], B = v[2];
v.erase(v.begin() + 1);
v.erase(v.begin() + 1);
v.insert(v.begin() + 1, {x, A[1], B[2]});
if (ok(v))
{
res.push_back({A[1], B[2], x});
return 1;
}
}
return 0;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << "DA\n1 3 3\n";
return 0;
cin >> n;
vector<array<int, 3>> v;
for (int i = 0; i < n; i++)
{
char ch;
cin >> ch;
v.push_back({ch - '0', i + 1, (i + 1) % n + 1});
}
if (!ok(v)) cout << "NE\n";
else
{
cout << "DA\n";
for (array<int, 3> &x : res) cout << x[0] << ' ' << x[1] << ' ' << x[2] << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |