Submission #674332

# Submission time Handle Problem Language Result Execution time Memory
674332 2022-12-23T17:41:48 Z null_awe Stray Cat (JOI20_stray) C++14
100 / 100
51 ms 16484 KB
#include "Anthony.h"
#include <bits/stdc++.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];
        }
      }
    }
    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;
    }
  }
  return color;
}

#include "Catherine.h"
#include <bits/stdc++.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() {
  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];
        }
      }
      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];
            }
          }
          return 0;
        }
        for (int i = 0; i < y.size(); ++i) {
          if (y[i] != prv) {
            start = true;
            return prv = y[i];
          }
        }
        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;
      }
      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:18:24: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   18 |       for (const auto& [u, i] : adj[v]) {
      |                        ^
Anthony.cpp:37:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |         for (const auto& [u, i] : adj[cur]) {
      |                          ^
Anthony.cpp:42:33: warning: unused variable 'v2' [-Wunused-variable]
   42 |       int v1 = dist[lp[p]] % 2, v2 = dist[cur] % 2;
      |                                 ^~
Anthony.cpp:57:24: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   57 |       for (const auto& [u, i] : adj[v]) {
      |                        ^
Anthony.cpp:70:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   70 |     for (const auto& [u, i] : adj[v]) {
      |                      ^

Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:28:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for (int i = 0; i < copy.size(); ++i)
      |                   ~~^~~~~~~~~~~~~
Catherine.cpp:35:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |       for (int i = 0; i < y.size(); ++i) {
      |                       ~~^~~~~~~~~~
Catherine.cpp:49:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         if (sum == 0 || sum == y.size()) {
      |                         ~~~~^~~~~~~~~~~
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 |           for (int i = 0; i < y.size(); ++i) {
      |                           ~~^~~~~~~~~~
Catherine.cpp:63:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for (int i = 0; i < y.size(); ++i) {
      |                         ~~^~~~~~~~~~
Catherine.cpp:90:46: warning: comparison of integer expressions of different signedness: 'const int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |   if (max(count[0], max(count[1], count[2])) == y.size()) return y[0];
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 15540 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 30 ms 14820 KB Output is correct
4 Correct 51 ms 16484 KB Output is correct
5 Correct 44 ms 16468 KB Output is correct
6 Correct 34 ms 15256 KB Output is correct
7 Correct 34 ms 15152 KB Output is correct
8 Correct 40 ms 15952 KB Output is correct
9 Correct 41 ms 16060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 15540 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 30 ms 14820 KB Output is correct
4 Correct 51 ms 16484 KB Output is correct
5 Correct 44 ms 16468 KB Output is correct
6 Correct 34 ms 15256 KB Output is correct
7 Correct 34 ms 15152 KB Output is correct
8 Correct 40 ms 15952 KB Output is correct
9 Correct 41 ms 16060 KB Output is correct
10 Correct 32 ms 13312 KB Output is correct
11 Correct 32 ms 13368 KB Output is correct
12 Correct 32 ms 13236 KB Output is correct
13 Correct 31 ms 13324 KB Output is correct
14 Correct 32 ms 13632 KB Output is correct
15 Correct 40 ms 14004 KB Output is correct
16 Correct 41 ms 16112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 13216 KB Output is correct
2 Correct 1 ms 524 KB Output is correct
3 Correct 27 ms 12728 KB Output is correct
4 Correct 44 ms 14380 KB Output is correct
5 Correct 43 ms 14268 KB Output is correct
6 Correct 32 ms 13076 KB Output is correct
7 Correct 33 ms 13072 KB Output is correct
8 Correct 39 ms 13756 KB Output is correct
9 Correct 39 ms 13724 KB Output is correct
10 Correct 35 ms 13504 KB Output is correct
11 Correct 39 ms 13424 KB Output is correct
12 Correct 39 ms 13448 KB Output is correct
13 Correct 39 ms 13448 KB Output is correct
14 Correct 38 ms 13792 KB Output is correct
15 Correct 38 ms 13824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 13216 KB Output is correct
2 Correct 1 ms 524 KB Output is correct
3 Correct 27 ms 12728 KB Output is correct
4 Correct 44 ms 14380 KB Output is correct
5 Correct 43 ms 14268 KB Output is correct
6 Correct 32 ms 13076 KB Output is correct
7 Correct 33 ms 13072 KB Output is correct
8 Correct 39 ms 13756 KB Output is correct
9 Correct 39 ms 13724 KB Output is correct
10 Correct 35 ms 13504 KB Output is correct
11 Correct 39 ms 13424 KB Output is correct
12 Correct 39 ms 13448 KB Output is correct
13 Correct 39 ms 13448 KB Output is correct
14 Correct 38 ms 13792 KB Output is correct
15 Correct 38 ms 13824 KB Output is correct
16 Correct 28 ms 11508 KB Output is correct
17 Correct 28 ms 11592 KB Output is correct
18 Correct 30 ms 11424 KB Output is correct
19 Correct 30 ms 11428 KB Output is correct
20 Correct 35 ms 12044 KB Output is correct
21 Correct 36 ms 11832 KB Output is correct
22 Correct 39 ms 13876 KB Output is correct
23 Correct 31 ms 11500 KB Output is correct
24 Correct 32 ms 11532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 908 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 2 ms 908 KB Output is correct
4 Correct 2 ms 908 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 900 KB Output is correct
7 Correct 2 ms 900 KB Output is correct
8 Correct 2 ms 900 KB Output is correct
9 Correct 2 ms 908 KB Output is correct
10 Correct 2 ms 908 KB Output is correct
11 Correct 2 ms 908 KB Output is correct
12 Correct 2 ms 908 KB Output is correct
13 Correct 2 ms 856 KB Output is correct
14 Correct 2 ms 912 KB Output is correct
15 Correct 2 ms 868 KB Output is correct
16 Correct 2 ms 908 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 912 KB Output is correct
21 Correct 2 ms 900 KB Output is correct
22 Correct 2 ms 856 KB Output is correct
23 Correct 2 ms 904 KB Output is correct
24 Correct 2 ms 872 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 864 KB Output is correct
28 Correct 2 ms 912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 11704 KB Output is correct
2 Correct 36 ms 12032 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 30 ms 11324 KB Output is correct
5 Correct 41 ms 12608 KB Output is correct
6 Correct 41 ms 12580 KB Output is correct
7 Correct 34 ms 11696 KB Output is correct
8 Correct 32 ms 11708 KB Output is correct
9 Correct 44 ms 12532 KB Output is correct
10 Correct 51 ms 12544 KB Output is correct
11 Correct 40 ms 12656 KB Output is correct
12 Correct 39 ms 12548 KB Output is correct
13 Correct 40 ms 12544 KB Output is correct
14 Correct 40 ms 12528 KB Output is correct
15 Correct 41 ms 12604 KB Output is correct
16 Correct 41 ms 12564 KB Output is correct
17 Correct 37 ms 12260 KB Output is correct
18 Correct 37 ms 12216 KB Output is correct
19 Correct 38 ms 12336 KB Output is correct
20 Correct 42 ms 12248 KB Output is correct
21 Correct 38 ms 12324 KB Output is correct
22 Correct 39 ms 12248 KB Output is correct
23 Correct 33 ms 11656 KB Output is correct
24 Correct 34 ms 11720 KB Output is correct
25 Correct 33 ms 11836 KB Output is correct
26 Correct 35 ms 11744 KB Output is correct
27 Correct 37 ms 12468 KB Output is correct
28 Correct 37 ms 12348 KB Output is correct
29 Correct 40 ms 12228 KB Output is correct
30 Correct 37 ms 12248 KB Output is correct
31 Correct 31 ms 11896 KB Output is correct
32 Correct 32 ms 11760 KB Output is correct
33 Correct 40 ms 11656 KB Output is correct
34 Correct 31 ms 11788 KB Output is correct
35 Correct 38 ms 12216 KB Output is correct
36 Correct 36 ms 12236 KB Output is correct
37 Correct 34 ms 12140 KB Output is correct
38 Correct 37 ms 12196 KB Output is correct
39 Correct 36 ms 12172 KB Output is correct
40 Correct 36 ms 12248 KB Output is correct
41 Correct 39 ms 12440 KB Output is correct
42 Correct 38 ms 12388 KB Output is correct
43 Correct 37 ms 12444 KB Output is correct
44 Correct 39 ms 12436 KB Output is correct
45 Correct 38 ms 12404 KB Output is correct
46 Correct 38 ms 12420 KB Output is correct
47 Correct 34 ms 12052 KB Output is correct
48 Correct 34 ms 12024 KB Output is correct
49 Correct 34 ms 12076 KB Output is correct
50 Correct 34 ms 12180 KB Output is correct
51 Correct 33 ms 12096 KB Output is correct
52 Correct 34 ms 12196 KB Output is correct
53 Correct 35 ms 12044 KB Output is correct
54 Correct 34 ms 12072 KB Output is correct
55 Correct 35 ms 12168 KB Output is correct
56 Correct 34 ms 12076 KB Output is correct
57 Correct 34 ms 11996 KB Output is correct
58 Correct 32 ms 12084 KB Output is correct
59 Correct 33 ms 11760 KB Output is correct
60 Correct 33 ms 11848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 11692 KB Output is correct
2 Correct 34 ms 11956 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 26 ms 11416 KB Output is correct
5 Correct 39 ms 12564 KB Output is correct
6 Correct 43 ms 12664 KB Output is correct
7 Correct 33 ms 11720 KB Output is correct
8 Correct 33 ms 11700 KB Output is correct
9 Correct 43 ms 12556 KB Output is correct
10 Correct 40 ms 12676 KB Output is correct
11 Correct 39 ms 12564 KB Output is correct
12 Correct 41 ms 12612 KB Output is correct
13 Correct 40 ms 12624 KB Output is correct
14 Correct 40 ms 12620 KB Output is correct
15 Correct 39 ms 12588 KB Output is correct
16 Correct 38 ms 12604 KB Output is correct
17 Correct 37 ms 12364 KB Output is correct
18 Correct 36 ms 12336 KB Output is correct
19 Correct 35 ms 12376 KB Output is correct
20 Correct 39 ms 12284 KB Output is correct
21 Correct 39 ms 12300 KB Output is correct
22 Correct 36 ms 12240 KB Output is correct
23 Correct 30 ms 11620 KB Output is correct
24 Correct 30 ms 11724 KB Output is correct
25 Correct 32 ms 11852 KB Output is correct
26 Correct 32 ms 11808 KB Output is correct
27 Correct 37 ms 12372 KB Output is correct
28 Correct 36 ms 12356 KB Output is correct
29 Correct 40 ms 12272 KB Output is correct
30 Correct 37 ms 12372 KB Output is correct
31 Correct 31 ms 11776 KB Output is correct
32 Correct 31 ms 11712 KB Output is correct
33 Correct 32 ms 11816 KB Output is correct
34 Correct 33 ms 12000 KB Output is correct
35 Correct 36 ms 12216 KB Output is correct
36 Correct 36 ms 12296 KB Output is correct
37 Correct 36 ms 12312 KB Output is correct
38 Correct 39 ms 12216 KB Output is correct
39 Correct 36 ms 12220 KB Output is correct
40 Correct 36 ms 12224 KB Output is correct
41 Correct 38 ms 12480 KB Output is correct
42 Correct 37 ms 12468 KB Output is correct
43 Correct 41 ms 12400 KB Output is correct
44 Correct 38 ms 12424 KB Output is correct
45 Correct 39 ms 12480 KB Output is correct
46 Correct 37 ms 12404 KB Output is correct
47 Correct 34 ms 12068 KB Output is correct
48 Correct 34 ms 12080 KB Output is correct
49 Correct 33 ms 11888 KB Output is correct
50 Correct 36 ms 12272 KB Output is correct
51 Correct 33 ms 12152 KB Output is correct
52 Correct 34 ms 12116 KB Output is correct
53 Correct 36 ms 12076 KB Output is correct
54 Correct 37 ms 12092 KB Output is correct
55 Correct 34 ms 12160 KB Output is correct
56 Correct 33 ms 12168 KB Output is correct
57 Correct 33 ms 12004 KB Output is correct
58 Correct 33 ms 12088 KB Output is correct
59 Correct 33 ms 11636 KB Output is correct
60 Correct 32 ms 11344 KB Output is correct