답안 #1004221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1004221 2024-06-21T06:32:29 Z aykhn Trobojnica (COCI19_trobojnica) C++17
0 / 110
0 ms 348 KB
#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];
  }
  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.erase(v.begin());
    v.insert(v.begin(), B);
    v.insert(v.begin(), A);
  }
  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;
    }
    v.erase(v.begin() + 1);
    v.insert(v.begin() + 1, B);
    v.insert(v.begin() + 1, A);
  }
  return 0;
}


signed main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(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';
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -