답안 #637254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637254 2022-09-01T07:38:49 Z iee Trobojnica (COCI19_trobojnica) C++17
110 / 110
58 ms 5324 KB
// iee
#include <bits/stdc++.h>

#define rep(i, a, b) for (auto i = (a); i <= (b); ++i)
#define per(i, a, b) for (auto i = (a); i >= (b); --i)
#define fi first
#define se second
using ll = long long;
using ull = unsigned long long;
using namespace std;
void work(int);

template <class T> void read(T &x) {
  x = 0; int f = 1, ch = getchar();
  while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
  while (isdigit(ch)) x = x * 10 + (ch - '0'), ch = getchar();
  x *= f;
}

int main() {
  int TT = 1; // cin >> TT;
  rep(CAS, 1, TT)
    work(CAS);
  return 0;
}
const int N = 2e5 + 5;
int n;
char s[N];
int nxt[N], col[N], cnt[5];
void work(int CASE) {
  read(n);
  scanf("%s", s);
  rep(i, 0, n - 1) ++cnt[col[i] = s[i] - '0'], nxt[i] = (i + 1) % n;
  rep(i, 1, 3) if (cnt[i] == n || cnt[i] % 2 != (n - 2) % 2) { puts("NE"); return; }
  puts("DA");
  int idx = 0;
  rep(t, 1, n - 3) {
    while (col[idx] == col[nxt[idx]] || cnt[col[idx]] == 1 && cnt[col[nxt[idx]]] == 1) idx = nxt[idx];
    int c = 6 - col[idx] - col[nxt[idx]];
    printf("%d %d %d\n", idx + 1, nxt[nxt[idx]] + 1, c);
    cnt[col[idx]]--, cnt[col[nxt[idx]]]--, cnt[c]++;
    nxt[idx] = nxt[nxt[idx]], col[idx] = c;
  }
}

Compilation message

trobojnica.cpp: In function 'void work(int)':
trobojnica.cpp:38:60: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   38 |     while (col[idx] == col[nxt[idx]] || cnt[col[idx]] == 1 && cnt[col[nxt[idx]]] == 1) idx = nxt[idx];
      |                                         ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
trobojnica.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   scanf("%s", s);
      |   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 58 ms 5324 KB Output is correct
22 Correct 46 ms 4236 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 44 ms 5152 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 22 ms 2588 KB Output is correct
28 Correct 3 ms 2260 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 3 ms 2260 KB Output is correct