답안 #748701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748701 2023-05-26T18:23:46 Z piOOE 길고양이 (JOI20_stray) C++17
100 / 100
53 ms 16480 KB
#include "Anthony.h"
#include <bits/stdc++.h>

using namespace std;

std::vector<int> Mark(int N, int M, int A, int B,
                      std::vector<int> U, std::vector<int> V) {
    std::vector<int> X(M, -1);
    vector<vector<pair<int, int>>> adj(N);

    for (int i = 0; i < M; ++i) {
        adj[U[i]].push_back({V[i], i});
        adj[V[i]].push_back({U[i], i});
    }

    vector<int> dist(N, -1), par(N), e(N, -1), ord;
    dist[0] = 0;
    queue<int> q;
    q.push(0);

    while (!q.empty()) {
        int v = q.front();
        q.pop();
        ord.push_back(v);

        for (auto [to, i] : adj[v]) {
            if (dist[to] == -1) {
                dist[to] = dist[v] + 1;
                par[to] = v;
                e[to] = i;
                q.push(to);
            }
        }
    }

    if (A >= 3) {
        for (int i = 0; i < M; ++i) {
            if (dist[U[i]] > dist[V[i]]) {
                swap(U[i], V[i]);
            }
            X[i] = dist[U[i]] % 3;
        }
    } else {
        vector<int> code{0, 1, 0, 0, 1, 1};
        vector<int> dp(N, -1);

        for (int x : ord) {
            if (par[x] && adj[par[x]].size() >= 3) {
                if (X[e[par[x]]] == 1) {
                    dp[x] = 0;
                } else {
                    dp[x] = 1;
                }
            } else if (x == 0) {
                dp[x] = -1;
            } else {
                dp[x] = (1 + dp[par[x]]) % size(code);
            }

            if (dp[x] >= 0) {
                X[e[x]] = code[dp[x]];
            }
        }
    }

    assert(find(X.begin(), X.end(), -1) == X.end());

    return X;
}
#include "Catherine.h"
#include <assert.h>
#include <algorithm>
#include <string>
#include <vector>

namespace {

  using std::string;

  int A, B;
  int last = -1;
  bool known = false;
  string seq = "";

}  // namespace

void Init(int A, int B) {
  ::A = A;
  ::B = B;
}

int Move(std::vector<int> y) {
  int ans = -2;
  auto yy = y;
  if (last != -1) {
    ++yy[last];
  }
  if (A == 2) {
    int deg = 0;
    for (int k = 0; k < 2; ++k) {
      deg += yy[k];
    }
    if (deg == 2) {
      if (known) {
        assert(std::count(y.begin(), y.end(), 1) == 1);
        ans = std::find(y.begin(), y.end(), 1) - y.begin();
      } else {
        for (int k = 0; k < 2; ++k) {
          seq += string(y[k], static_cast<char>('0' + k));
        }
        if (seq.size() == 5) {
          bool rev = false;
          for (int rot = 0; rot < 6; ++rot) {
            if (seq == string("010011010011").substr(rot, 5)) {
              rev = true;
            }
          }
          known = true;
          if (rev) {
            ans = -1;
          } else {
            assert(std::count(y.begin(), y.end(), 1) == 1);
            ans = std::find(y.begin(), y.end(), 1) - y.begin();
          }
        } else {
          ans = seq.back() - '0';
        }
      }
    } else {
      known = true;
      assert(std::count(yy.begin(), yy.end(), 1) == 1);
      ans = std::find(yy.begin(), yy.end(), 1) - yy.begin();
      if (ans == last) {
        ans = -1;
      }
    }
  } else {
    int flag = 0;
    for (int k = 0; k < 3; ++k) {
      if (yy[k] > 0) {
        flag |= 1 << k;
      }
    }
    switch (flag) {
      case 0b001: case 0b011: ans = 0; break;
      case 0b010: case 0b110: ans = 1; break;
      case 0b100: case 0b101: ans = 2; break;
      default: assert(false);
    }
  }
  if (ans != -1) {
    last = ans;
  }
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 15400 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 30 ms 14844 KB Output is correct
4 Correct 45 ms 16480 KB Output is correct
5 Correct 48 ms 16412 KB Output is correct
6 Correct 35 ms 15164 KB Output is correct
7 Correct 35 ms 15232 KB Output is correct
8 Correct 41 ms 15952 KB Output is correct
9 Correct 41 ms 15844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 15400 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 30 ms 14844 KB Output is correct
4 Correct 45 ms 16480 KB Output is correct
5 Correct 48 ms 16412 KB Output is correct
6 Correct 35 ms 15164 KB Output is correct
7 Correct 35 ms 15232 KB Output is correct
8 Correct 41 ms 15952 KB Output is correct
9 Correct 41 ms 15844 KB Output is correct
10 Correct 33 ms 13160 KB Output is correct
11 Correct 34 ms 13156 KB Output is correct
12 Correct 36 ms 13220 KB Output is correct
13 Correct 32 ms 13276 KB Output is correct
14 Correct 35 ms 13356 KB Output is correct
15 Correct 38 ms 13808 KB Output is correct
16 Correct 42 ms 15952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 13116 KB Output is correct
2 Correct 0 ms 520 KB Output is correct
3 Correct 28 ms 12624 KB Output is correct
4 Correct 43 ms 14236 KB Output is correct
5 Correct 43 ms 14264 KB Output is correct
6 Correct 34 ms 13056 KB Output is correct
7 Correct 34 ms 13020 KB Output is correct
8 Correct 39 ms 13704 KB Output is correct
9 Correct 38 ms 13680 KB Output is correct
10 Correct 39 ms 13476 KB Output is correct
11 Correct 37 ms 13356 KB Output is correct
12 Correct 37 ms 13380 KB Output is correct
13 Correct 37 ms 13400 KB Output is correct
14 Correct 41 ms 13644 KB Output is correct
15 Correct 40 ms 13660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 13116 KB Output is correct
2 Correct 0 ms 520 KB Output is correct
3 Correct 28 ms 12624 KB Output is correct
4 Correct 43 ms 14236 KB Output is correct
5 Correct 43 ms 14264 KB Output is correct
6 Correct 34 ms 13056 KB Output is correct
7 Correct 34 ms 13020 KB Output is correct
8 Correct 39 ms 13704 KB Output is correct
9 Correct 38 ms 13680 KB Output is correct
10 Correct 39 ms 13476 KB Output is correct
11 Correct 37 ms 13356 KB Output is correct
12 Correct 37 ms 13380 KB Output is correct
13 Correct 37 ms 13400 KB Output is correct
14 Correct 41 ms 13644 KB Output is correct
15 Correct 40 ms 13660 KB Output is correct
16 Correct 30 ms 11480 KB Output is correct
17 Correct 31 ms 11492 KB Output is correct
18 Correct 31 ms 11388 KB Output is correct
19 Correct 31 ms 11352 KB Output is correct
20 Correct 40 ms 11804 KB Output is correct
21 Correct 34 ms 11672 KB Output is correct
22 Correct 41 ms 13820 KB Output is correct
23 Correct 34 ms 11400 KB Output is correct
24 Correct 33 ms 11472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 904 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 2 ms 896 KB Output is correct
4 Correct 2 ms 908 KB Output is correct
5 Correct 2 ms 904 KB Output is correct
6 Correct 2 ms 896 KB Output is correct
7 Correct 2 ms 904 KB Output is correct
8 Correct 2 ms 896 KB Output is correct
9 Correct 2 ms 896 KB Output is correct
10 Correct 2 ms 904 KB Output is correct
11 Correct 2 ms 896 KB Output is correct
12 Correct 2 ms 904 KB Output is correct
13 Correct 2 ms 896 KB Output is correct
14 Correct 2 ms 904 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 2 ms 900 KB Output is correct
17 Correct 2 ms 904 KB Output is correct
18 Correct 2 ms 900 KB Output is correct
19 Correct 2 ms 896 KB Output is correct
20 Correct 2 ms 896 KB Output is correct
21 Correct 2 ms 904 KB Output is correct
22 Correct 2 ms 896 KB Output is correct
23 Correct 2 ms 904 KB Output is correct
24 Correct 2 ms 896 KB Output is correct
25 Correct 2 ms 900 KB Output is correct
26 Correct 2 ms 908 KB Output is correct
27 Correct 2 ms 896 KB Output is correct
28 Correct 2 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 11228 KB Output is correct
2 Correct 35 ms 11656 KB Output is correct
3 Correct 0 ms 508 KB Output is correct
4 Correct 30 ms 10944 KB Output is correct
5 Correct 41 ms 12244 KB Output is correct
6 Correct 48 ms 12208 KB Output is correct
7 Correct 34 ms 11376 KB Output is correct
8 Correct 36 ms 11376 KB Output is correct
9 Correct 53 ms 12280 KB Output is correct
10 Correct 46 ms 12168 KB Output is correct
11 Correct 48 ms 12180 KB Output is correct
12 Correct 47 ms 12164 KB Output is correct
13 Correct 47 ms 12308 KB Output is correct
14 Correct 51 ms 12188 KB Output is correct
15 Correct 47 ms 12156 KB Output is correct
16 Correct 40 ms 12212 KB Output is correct
17 Correct 38 ms 11876 KB Output is correct
18 Correct 39 ms 11944 KB Output is correct
19 Correct 37 ms 11952 KB Output is correct
20 Correct 37 ms 12004 KB Output is correct
21 Correct 38 ms 11984 KB Output is correct
22 Correct 39 ms 11980 KB Output is correct
23 Correct 31 ms 11192 KB Output is correct
24 Correct 32 ms 11240 KB Output is correct
25 Correct 32 ms 11204 KB Output is correct
26 Correct 33 ms 11312 KB Output is correct
27 Correct 38 ms 11792 KB Output is correct
28 Correct 39 ms 11888 KB Output is correct
29 Correct 38 ms 11740 KB Output is correct
30 Correct 41 ms 11668 KB Output is correct
31 Correct 33 ms 11196 KB Output is correct
32 Correct 33 ms 11228 KB Output is correct
33 Correct 32 ms 11260 KB Output is correct
34 Correct 32 ms 11388 KB Output is correct
35 Correct 39 ms 11720 KB Output is correct
36 Correct 36 ms 11740 KB Output is correct
37 Correct 36 ms 11644 KB Output is correct
38 Correct 43 ms 11708 KB Output is correct
39 Correct 35 ms 11768 KB Output is correct
40 Correct 35 ms 11532 KB Output is correct
41 Correct 39 ms 11924 KB Output is correct
42 Correct 39 ms 11952 KB Output is correct
43 Correct 37 ms 11944 KB Output is correct
44 Correct 37 ms 11988 KB Output is correct
45 Correct 38 ms 11952 KB Output is correct
46 Correct 38 ms 11968 KB Output is correct
47 Correct 35 ms 11568 KB Output is correct
48 Correct 35 ms 11520 KB Output is correct
49 Correct 36 ms 11440 KB Output is correct
50 Correct 35 ms 11688 KB Output is correct
51 Correct 34 ms 11352 KB Output is correct
52 Correct 34 ms 11484 KB Output is correct
53 Correct 34 ms 11444 KB Output is correct
54 Correct 36 ms 11500 KB Output is correct
55 Correct 38 ms 11320 KB Output is correct
56 Correct 33 ms 11372 KB Output is correct
57 Correct 32 ms 11384 KB Output is correct
58 Correct 35 ms 11364 KB Output is correct
59 Correct 32 ms 11444 KB Output is correct
60 Correct 34 ms 11332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 11156 KB Output is correct
2 Correct 34 ms 11464 KB Output is correct
3 Correct 0 ms 516 KB Output is correct
4 Correct 28 ms 10976 KB Output is correct
5 Correct 44 ms 12332 KB Output is correct
6 Correct 42 ms 12220 KB Output is correct
7 Correct 34 ms 11348 KB Output is correct
8 Correct 34 ms 11388 KB Output is correct
9 Correct 41 ms 12260 KB Output is correct
10 Correct 41 ms 12148 KB Output is correct
11 Correct 39 ms 12300 KB Output is correct
12 Correct 43 ms 12284 KB Output is correct
13 Correct 41 ms 12296 KB Output is correct
14 Correct 41 ms 12316 KB Output is correct
15 Correct 39 ms 12272 KB Output is correct
16 Correct 40 ms 12172 KB Output is correct
17 Correct 37 ms 11976 KB Output is correct
18 Correct 38 ms 12024 KB Output is correct
19 Correct 38 ms 12000 KB Output is correct
20 Correct 41 ms 11840 KB Output is correct
21 Correct 39 ms 11932 KB Output is correct
22 Correct 39 ms 11928 KB Output is correct
23 Correct 31 ms 11096 KB Output is correct
24 Correct 31 ms 11100 KB Output is correct
25 Correct 32 ms 11368 KB Output is correct
26 Correct 32 ms 11380 KB Output is correct
27 Correct 37 ms 11756 KB Output is correct
28 Correct 36 ms 11728 KB Output is correct
29 Correct 37 ms 11800 KB Output is correct
30 Correct 37 ms 11768 KB Output is correct
31 Correct 35 ms 11184 KB Output is correct
32 Correct 32 ms 11228 KB Output is correct
33 Correct 32 ms 11368 KB Output is correct
34 Correct 33 ms 11328 KB Output is correct
35 Correct 36 ms 11764 KB Output is correct
36 Correct 39 ms 11704 KB Output is correct
37 Correct 38 ms 11696 KB Output is correct
38 Correct 37 ms 11696 KB Output is correct
39 Correct 39 ms 11804 KB Output is correct
40 Correct 35 ms 11772 KB Output is correct
41 Correct 40 ms 11936 KB Output is correct
42 Correct 36 ms 12004 KB Output is correct
43 Correct 37 ms 11904 KB Output is correct
44 Correct 40 ms 11932 KB Output is correct
45 Correct 42 ms 12000 KB Output is correct
46 Correct 43 ms 12068 KB Output is correct
47 Correct 34 ms 11588 KB Output is correct
48 Correct 39 ms 11564 KB Output is correct
49 Correct 36 ms 11480 KB Output is correct
50 Correct 37 ms 11636 KB Output is correct
51 Correct 33 ms 11436 KB Output is correct
52 Correct 34 ms 11408 KB Output is correct
53 Correct 34 ms 11368 KB Output is correct
54 Correct 33 ms 11344 KB Output is correct
55 Correct 36 ms 11404 KB Output is correct
56 Correct 34 ms 11360 KB Output is correct
57 Correct 33 ms 11432 KB Output is correct
58 Correct 34 ms 11376 KB Output is correct
59 Correct 34 ms 11316 KB Output is correct
60 Correct 33 ms 11376 KB Output is correct