답안 #674331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674331 2022-12-23T17:39:25 Z null_awe 길고양이 (JOI20_stray) C++14
100 / 100
51 ms 16144 KB
#include "Anthony.h"
#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <assert.h>
using namespace std;

#define pii pair<int, int>

vector<int> Mark(int n, int m, int a, int b, vector<int> u, vector<int> v) {
  vector<vector<pii>> 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});
  if (a == 2) {
    vector<int> color(m, -1), dist(n, -1), lp(n), llp(n);
    for (int i = 0; i < n; ++i) lp[i] = i, llp[i] = i;
    queue<int> q; q.push(0), dist[0] = 0;
    set<int> heads;
    while (q.size()) {
      int v = q.front(); q.pop();
      int label = dist[v] % 2;
      for (const auto& [u, i] : adj[v]) {
        if (color[i] >= 0) {
          if (adj[v].size() == 2) {
            lp[v] = lp[u];
            if (lp[u] == u) heads.insert(v);
            else llp[v] = llp[u];
          }
          continue;
        }
        color[i] = label;
        q.push(u), dist[u] = dist[v] + 1;
      }
    }
    vector<int> pat = {1, 1, 0, 0, 1, 0};
    vector<int> shifts(n);
    for (int p : heads) {
      int cur = p;
      while (true) {
        bool can = false;
        for (const auto& [u, i] : adj[cur]) {
          if (dist[u] > dist[cur] && adj[u].size() == 2) can = true, cur = u;
        }
        if (!can) break;
      }
      int v1 = dist[lp[p]] % 2, v2 = dist[cur] % 2;
      int dd = dist[cur] - dist[lp[p]];
      int shift = 0;
      if (dd % 6 == 0) shift = v1 ? 0 : 2;
      else if (dd % 6 == 1) shift = v1 ? 1 : 3;
      else if (dd % 6 == 2) shift = v1 ? 4 : 3;
      else if (dd % 6 == 3) shift = v1 ? 0 : 3;
      else if (dd % 6 == 4) shift = v1 ? 0 : 5;
      else shift = v1 ? 0 : 5;
      shifts[p] = shift;
    }
    for (int v = 1; v < n; ++v) {
      if (adj[v].size() != 2) continue;
      int p = lp[v];
      int shift = shifts[llp[v]];
      for (const auto& [u, i] : adj[v]) {
        if (dist[u] > dist[v]) {
          color[i] = pat[(dist[v] - dist[p] + shift) % 6];
        }
      }
    }
  //for (int i = 0; i < m; ++i) cout << color[i] << ' ';
  //cout << '\n';
    return color;
  }
  vector<int> color(m, -1), dist(n, -1);
  queue<int> q; q.push(0), dist[0] = 0;
  while (q.size()) {
    int v = q.front(); q.pop();
    int label = dist[v] % 3;
    for (const auto& [u, i] : adj[v]) {
      if (color[i] >= 0) continue;
      color[i] = label;
      if (dist[u] < 0) q.push(u), dist[u] = dist[v] + 1;
    }
  }
  for (int num : color) assert(num >= 0 && num < 3);
  return color;
}

#include "Catherine.h"
#include <iostream>
#include <vector>
#include <assert.h>
using namespace std;

int a;

void Init(int _a, int _b) {
  a = _a;
}

int prv = -1;
bool start = false;
vector<int> seen;

bool forwards() {
  assert(seen.size() == 5);
  vector<int> f1 = {0, 1, 0, 0, 1};
  vector<int> f2 = {1, 0, 0, 1, 1};
  vector<int> f3 = {0, 0, 1, 1, 0};
  vector<int> f4 = {0, 1, 1, 0, 1};
  vector<int> f5 = {1, 1, 0, 1, 0};
  vector<int> f6 = {1, 0, 1, 0, 0};
  return seen == f1 || seen == f2 || seen == f3 || seen == f4 || seen == f5 || seen == f6;
}

int Move(vector<int> y) {
  vector<int> copy = y;
  y.clear();
  for (int i = 0; i < copy.size(); ++i)
    for (int j = 0; j < copy[i]; ++j) y.push_back(i);
  if (a == 2) {
    if (start) {
      if (y.size() == 1) {
        return prv = y[0];
      }
      for (int i = 0; i < y.size(); ++i) {
        if (y[i] != prv) {
          return prv = y[i];
        }
      }
      // Shouldn't ever happen:
      //cout << copy[0] << ' ' << copy[1] << endl;
      assert(0);
      return 0;
    } else {
      if (y.size() > 1) {
        int sum = 0;
        for (int num : y) sum += num;
        if (prv == -1 && y.size() == 2) {
          seen.push_back(y[0]), seen.push_back(y[1]);
          return prv = y[1];
        }
        if (sum == 0 || sum == y.size()) {
          start = true;
          return -1;
        }
        if (prv == -1) {
          int find = sum == 1;
          for (int i = 0; i < y.size(); ++i) {
            if (y[i] == find) {
              start = true;
              return prv = y[i];
            }
          }
          // Shouldn't ever happen:
          assert(0);
          return 0;
        }
        for (int i = 0; i < y.size(); ++i) {
          if (y[i] != prv) {
            start = true;
            return prv = y[i];
          }
        }
        // Shouldn't ever happen:
        assert(0);
        return 0;
      } else {
        if (y.size() == 0) {
          start = true;
          return -1;
        }
        seen.push_back(y[0]);
        if (seen.size() < 5) {
          return prv = y[0];
        }
        start = true;
        if (forwards()) {
          return prv = y[0];
        }
        return -1;
      }
      // Shouldn't ever happen:
      assert(0);
      return 0;
    }
  }
  vector<int> count(3);
  for (int num : y) ++count[num];
  if (max(count[0], max(count[1], count[2])) == y.size()) return y[0];
  return !count[0] ? 1 : (!count[1] ? 2 : 0);
}

Compilation message

Anthony.cpp: In function 'std::vector<int> Mark(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:22:24: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   22 |       for (const auto& [u, i] : adj[v]) {
      |                        ^
Anthony.cpp:41:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |         for (const auto& [u, i] : adj[cur]) {
      |                          ^
Anthony.cpp:46:33: warning: unused variable 'v2' [-Wunused-variable]
   46 |       int v1 = dist[lp[p]] % 2, v2 = dist[cur] % 2;
      |                                 ^~
Anthony.cpp:61:24: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |       for (const auto& [u, i] : adj[v]) {
      |                        ^
Anthony.cpp:76:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   76 |     for (const auto& [u, i] : adj[v]) {
      |                      ^

Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:31:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for (int i = 0; i < copy.size(); ++i)
      |                   ~~^~~~~~~~~~~~~
Catherine.cpp:38:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |       for (int i = 0; i < y.size(); ++i) {
      |                       ~~^~~~~~~~~~
Catherine.cpp:55:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         if (sum == 0 || sum == y.size()) {
      |                         ~~~~^~~~~~~~~~~
Catherine.cpp:61:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |           for (int i = 0; i < y.size(); ++i) {
      |                           ~~^~~~~~~~~~
Catherine.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for (int i = 0; i < y.size(); ++i) {
      |                         ~~^~~~~~~~~~
Catherine.cpp:102:46: warning: comparison of integer expressions of different signedness: 'const int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |   if (max(count[0], max(count[1], count[2])) == y.size()) return y[0];
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 15080 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 28 ms 14420 KB Output is correct
4 Correct 48 ms 16144 KB Output is correct
5 Correct 51 ms 16020 KB Output is correct
6 Correct 36 ms 14912 KB Output is correct
7 Correct 37 ms 14804 KB Output is correct
8 Correct 41 ms 15576 KB Output is correct
9 Correct 42 ms 15628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 15080 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 28 ms 14420 KB Output is correct
4 Correct 48 ms 16144 KB Output is correct
5 Correct 51 ms 16020 KB Output is correct
6 Correct 36 ms 14912 KB Output is correct
7 Correct 37 ms 14804 KB Output is correct
8 Correct 41 ms 15576 KB Output is correct
9 Correct 42 ms 15628 KB Output is correct
10 Correct 30 ms 12868 KB Output is correct
11 Correct 30 ms 12844 KB Output is correct
12 Correct 31 ms 13008 KB Output is correct
13 Correct 31 ms 12844 KB Output is correct
14 Correct 33 ms 13284 KB Output is correct
15 Correct 36 ms 13524 KB Output is correct
16 Correct 39 ms 15560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 12668 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 30 ms 12264 KB Output is correct
4 Correct 46 ms 13808 KB Output is correct
5 Correct 41 ms 13916 KB Output is correct
6 Correct 31 ms 12748 KB Output is correct
7 Correct 33 ms 12568 KB Output is correct
8 Correct 39 ms 13216 KB Output is correct
9 Correct 39 ms 13272 KB Output is correct
10 Correct 37 ms 13016 KB Output is correct
11 Correct 34 ms 13040 KB Output is correct
12 Correct 35 ms 13052 KB Output is correct
13 Correct 35 ms 13044 KB Output is correct
14 Correct 40 ms 13432 KB Output is correct
15 Correct 40 ms 13340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 12668 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 30 ms 12264 KB Output is correct
4 Correct 46 ms 13808 KB Output is correct
5 Correct 41 ms 13916 KB Output is correct
6 Correct 31 ms 12748 KB Output is correct
7 Correct 33 ms 12568 KB Output is correct
8 Correct 39 ms 13216 KB Output is correct
9 Correct 39 ms 13272 KB Output is correct
10 Correct 37 ms 13016 KB Output is correct
11 Correct 34 ms 13040 KB Output is correct
12 Correct 35 ms 13052 KB Output is correct
13 Correct 35 ms 13044 KB Output is correct
14 Correct 40 ms 13432 KB Output is correct
15 Correct 40 ms 13340 KB Output is correct
16 Correct 28 ms 11064 KB Output is correct
17 Correct 28 ms 11124 KB Output is correct
18 Correct 28 ms 11000 KB Output is correct
19 Correct 30 ms 10988 KB Output is correct
20 Correct 34 ms 11624 KB Output is correct
21 Correct 32 ms 11360 KB Output is correct
22 Correct 37 ms 13388 KB Output is correct
23 Correct 32 ms 11108 KB Output is correct
24 Correct 32 ms 11116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 1 ms 896 KB Output is correct
4 Correct 2 ms 904 KB Output is correct
5 Correct 2 ms 904 KB Output is correct
6 Correct 2 ms 904 KB Output is correct
7 Correct 2 ms 900 KB Output is correct
8 Correct 2 ms 856 KB Output is correct
9 Correct 2 ms 912 KB Output is correct
10 Correct 2 ms 908 KB Output is correct
11 Correct 2 ms 912 KB Output is correct
12 Correct 2 ms 900 KB Output is correct
13 Correct 2 ms 900 KB Output is correct
14 Correct 2 ms 900 KB Output is correct
15 Correct 2 ms 912 KB Output is correct
16 Correct 2 ms 900 KB Output is correct
17 Correct 2 ms 864 KB Output is correct
18 Correct 2 ms 908 KB Output is correct
19 Correct 2 ms 908 KB Output is correct
20 Correct 2 ms 900 KB Output is correct
21 Correct 2 ms 900 KB Output is correct
22 Correct 2 ms 996 KB Output is correct
23 Correct 2 ms 908 KB Output is correct
24 Correct 2 ms 868 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 2 ms 864 KB Output is correct
27 Correct 2 ms 908 KB Output is correct
28 Correct 2 ms 900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 11392 KB Output is correct
2 Correct 39 ms 11740 KB Output is correct
3 Correct 1 ms 516 KB Output is correct
4 Correct 28 ms 10980 KB Output is correct
5 Correct 45 ms 12188 KB Output is correct
6 Correct 41 ms 12060 KB Output is correct
7 Correct 32 ms 11692 KB Output is correct
8 Correct 33 ms 11592 KB Output is correct
9 Correct 39 ms 12508 KB Output is correct
10 Correct 40 ms 12524 KB Output is correct
11 Correct 38 ms 12528 KB Output is correct
12 Correct 39 ms 12600 KB Output is correct
13 Correct 39 ms 12536 KB Output is correct
14 Correct 38 ms 12604 KB Output is correct
15 Correct 41 ms 12560 KB Output is correct
16 Correct 40 ms 12604 KB Output is correct
17 Correct 38 ms 12288 KB Output is correct
18 Correct 36 ms 12300 KB Output is correct
19 Correct 37 ms 12300 KB Output is correct
20 Correct 36 ms 12216 KB Output is correct
21 Correct 38 ms 12280 KB Output is correct
22 Correct 36 ms 12264 KB Output is correct
23 Correct 31 ms 11820 KB Output is correct
24 Correct 32 ms 11724 KB Output is correct
25 Correct 33 ms 11716 KB Output is correct
26 Correct 31 ms 11816 KB Output is correct
27 Correct 37 ms 12336 KB Output is correct
28 Correct 39 ms 12276 KB Output is correct
29 Correct 36 ms 12208 KB Output is correct
30 Correct 37 ms 12252 KB Output is correct
31 Correct 31 ms 11888 KB Output is correct
32 Correct 31 ms 11816 KB Output is correct
33 Correct 32 ms 11752 KB Output is correct
34 Correct 31 ms 11840 KB Output is correct
35 Correct 36 ms 12160 KB Output is correct
36 Correct 36 ms 12188 KB Output is correct
37 Correct 35 ms 12268 KB Output is correct
38 Correct 36 ms 12204 KB Output is correct
39 Correct 38 ms 12304 KB Output is correct
40 Correct 34 ms 12304 KB Output is correct
41 Correct 40 ms 12428 KB Output is correct
42 Correct 37 ms 12456 KB Output is correct
43 Correct 38 ms 12456 KB Output is correct
44 Correct 38 ms 12360 KB Output is correct
45 Correct 40 ms 12448 KB Output is correct
46 Correct 39 ms 12400 KB Output is correct
47 Correct 39 ms 12044 KB Output is correct
48 Correct 36 ms 11996 KB Output is correct
49 Correct 34 ms 11960 KB Output is correct
50 Correct 37 ms 12052 KB Output is correct
51 Correct 35 ms 12076 KB Output is correct
52 Correct 34 ms 12192 KB Output is correct
53 Correct 33 ms 12016 KB Output is correct
54 Correct 32 ms 12088 KB Output is correct
55 Correct 40 ms 12132 KB Output is correct
56 Correct 32 ms 12168 KB Output is correct
57 Correct 32 ms 12024 KB Output is correct
58 Correct 33 ms 12048 KB Output is correct
59 Correct 32 ms 11916 KB Output is correct
60 Correct 32 ms 11820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 11288 KB Output is correct
2 Correct 33 ms 11592 KB Output is correct
3 Correct 0 ms 508 KB Output is correct
4 Correct 26 ms 10992 KB Output is correct
5 Correct 41 ms 12072 KB Output is correct
6 Correct 43 ms 12136 KB Output is correct
7 Correct 34 ms 11692 KB Output is correct
8 Correct 33 ms 11688 KB Output is correct
9 Correct 40 ms 12472 KB Output is correct
10 Correct 40 ms 12472 KB Output is correct
11 Correct 38 ms 12628 KB Output is correct
12 Correct 40 ms 12604 KB Output is correct
13 Correct 38 ms 12584 KB Output is correct
14 Correct 39 ms 12508 KB Output is correct
15 Correct 41 ms 12528 KB Output is correct
16 Correct 38 ms 12628 KB Output is correct
17 Correct 38 ms 12340 KB Output is correct
18 Correct 44 ms 12304 KB Output is correct
19 Correct 37 ms 12200 KB Output is correct
20 Correct 41 ms 12292 KB Output is correct
21 Correct 36 ms 12300 KB Output is correct
22 Correct 36 ms 12292 KB Output is correct
23 Correct 34 ms 11668 KB Output is correct
24 Correct 32 ms 11700 KB Output is correct
25 Correct 33 ms 11808 KB Output is correct
26 Correct 32 ms 11792 KB Output is correct
27 Correct 37 ms 12216 KB Output is correct
28 Correct 38 ms 12216 KB Output is correct
29 Correct 37 ms 12272 KB Output is correct
30 Correct 37 ms 12344 KB Output is correct
31 Correct 31 ms 11772 KB Output is correct
32 Correct 32 ms 11876 KB Output is correct
33 Correct 32 ms 11824 KB Output is correct
34 Correct 33 ms 11820 KB Output is correct
35 Correct 36 ms 12180 KB Output is correct
36 Correct 40 ms 12372 KB Output is correct
37 Correct 38 ms 12196 KB Output is correct
38 Correct 36 ms 12316 KB Output is correct
39 Correct 37 ms 12284 KB Output is correct
40 Correct 36 ms 12172 KB Output is correct
41 Correct 38 ms 12480 KB Output is correct
42 Correct 37 ms 12336 KB Output is correct
43 Correct 38 ms 12356 KB Output is correct
44 Correct 41 ms 12472 KB Output is correct
45 Correct 38 ms 12392 KB Output is correct
46 Correct 40 ms 12400 KB Output is correct
47 Correct 34 ms 12084 KB Output is correct
48 Correct 34 ms 12088 KB Output is correct
49 Correct 39 ms 11964 KB Output is correct
50 Correct 34 ms 12216 KB Output is correct
51 Correct 34 ms 12132 KB Output is correct
52 Correct 34 ms 12092 KB Output is correct
53 Correct 34 ms 12144 KB Output is correct
54 Correct 34 ms 12124 KB Output is correct
55 Correct 34 ms 12052 KB Output is correct
56 Correct 35 ms 12200 KB Output is correct
57 Correct 33 ms 12032 KB Output is correct
58 Correct 34 ms 12032 KB Output is correct
59 Correct 33 ms 11844 KB Output is correct
60 Correct 32 ms 11836 KB Output is correct