Submission #802688

# Submission time Handle Problem Language Result Execution time Memory
802688 2023-08-02T13:23:04 Z Um_nik Stray Cat (JOI20_stray) C++17
20 / 100
53 ms 16260 KB
#include "Anthony.h"
#include <vector>
#include <cassert>
using namespace std;

using pii = pair<int, int>;

namespace {

}  // namespace

vector<int> Mark(int N, int M, int A, int B,
                      vector<int> U, vector<int> V) {
  vector<int> X(M, -1);
  vector<vector<pii>> g(N, vector<pii>());
  for (int i = 0; i < M; i++) {
    int u = U[i], v = V[i];
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  vector<int> dist(N, N);
  dist[0] = 0;
  vector<int> q;
  q.push_back(0);
  for (int i = 0; i < (int)q.size(); i++) {
    int v = q[i];
    for (pii e : g[v]) if (dist[e.first] == N) {
      dist[e.first] = dist[v] + 1;
      q.push_back(e.first);
    }
  }
  assert((int)q.size() == N);

  if (A >= 3) {
    for (int i = 0; i < M; i++)
      X[i] = min(dist[U[i]], dist[V[i]]) % 3;
  } else {
    assert(M == N - 1);
    vector<int> posInBamboo(N, -1);
    for (int i = 0; i < N; i++) {
      int v = q[i];
      if (i == 0) {
        for (auto [u, id] : g[v]) {
          X[id] = 0;
        }
        continue;
      }
      int deg = (int)g[v].size();
      if (deg == 1) continue;
      int par = -1;
      int parC = -1;
      for (auto [u, id] : g[v]) if (dist[u] < dist[v]) {
        par = u;
        parC = X[id];
      }
      if (deg == 2) {
        if (posInBamboo[par] != -1) {
          posInBamboo[v] = (posInBamboo[par] + 1) % 6;
        } else {
          posInBamboo[v] = parC + 1;
        }
        int col = (posInBamboo[v] == 0 || posInBamboo[v] == 2 || posInBamboo[v] == 3 ? 0 : 1);
        for (auto [u, id] : g[v]) if (u != par)
          X[id] = col;
      } else {
        for (auto [u, id] : g[v]) if (u != par)
          X[id] = parC ^ 1;
      }
    }
  }
  return X;
}
#include "Catherine.h"
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;

namespace {

int A;
bool bambooPart;
vector<int> colors;

bool GoingUp(vector<int> s) {
  vector<int> t = {1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0};
  reverse(t.begin(), t.end());
  for (int i = 0; i + (int)s.size() <= (int)t.size(); i++) {
    bool ok = true;
    for (int j = 0; j < (int)s.size(); j++)
      ok &= s[j] == t[i + j];
    if (ok) return true;
  }
  return false;
}

}  // namespace

void Init(int A, int B) {
  ::A = A;
  ::bambooPart = true;
  ::colors = vector<int>();
}

int Move(std::vector<int> y) {
  if (::A > 2) {
    int c = 0;
    while(c < 3) {
      if (y[c] > 0 && y[(c + 2) % 3] == 0) break;
      c++;
    }
    assert(c < 3);
    return c;
  } else {
    if (!::colors.empty()) y[::colors.back()]++;
    int deg = y[0] + y[1];
    int col = -2;
    if (deg == 1) {
      ::bambooPart = false;
      if (::colors.empty()) {
        col = (y[0] > 0 ? 0 : 1);
      } else {
        col = -1;
      }
    } else if (deg == 2) {
      if (!::bambooPart) {
        assert(!::colors.empty());
        y[::colors.back()]--;
        col = (y[0] > 0 ? 0 : 1);
      } else {
        if ((int)::colors.size() < 3) {
          if (!::colors.empty()) y[::colors.back()]--;
          col = (y[0] > 0 ? 0 : 1);
        } else {
          y[::colors.back()]--;
          col = (y[0] > 0 ? 0 : 1);
          vector<int> s = ::colors;
          s.push_back(col);
          if (!::GoingUp(s)) col = -1;
          ::bambooPart = false;
        }
      }
    } else {
      assert(deg > 2);
      ::bambooPart = false;
      col = (y[0] == 1 ? 0 : 1);
      assert(y[col] == 1);
      if (!::colors.empty() && ::colors.back() == col) col = -1;
    }
    if (col == -1) {
      int x = ::colors.back();
      ::colors.push_back(x);
    } else {
      ::colors.push_back(col);
    }
    return col;
  }
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 15284 KB Output is correct
2 Correct 0 ms 504 KB Output is correct
3 Correct 28 ms 14504 KB Output is correct
4 Correct 53 ms 16244 KB Output is correct
5 Correct 52 ms 16260 KB Output is correct
6 Correct 34 ms 15064 KB Output is correct
7 Correct 35 ms 15068 KB Output is correct
8 Correct 41 ms 15744 KB Output is correct
9 Correct 36 ms 15796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 15284 KB Output is correct
2 Correct 0 ms 504 KB Output is correct
3 Correct 28 ms 14504 KB Output is correct
4 Correct 53 ms 16244 KB Output is correct
5 Correct 52 ms 16260 KB Output is correct
6 Correct 34 ms 15064 KB Output is correct
7 Correct 35 ms 15068 KB Output is correct
8 Correct 41 ms 15744 KB Output is correct
9 Correct 36 ms 15796 KB Output is correct
10 Correct 33 ms 12984 KB Output is correct
11 Correct 26 ms 13004 KB Output is correct
12 Correct 26 ms 13116 KB Output is correct
13 Correct 26 ms 13100 KB Output is correct
14 Correct 26 ms 13332 KB Output is correct
15 Correct 36 ms 13720 KB Output is correct
16 Correct 34 ms 15764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 12840 KB Output is correct
2 Correct 1 ms 516 KB Output is correct
3 Correct 29 ms 12336 KB Output is correct
4 Correct 32 ms 14144 KB Output is correct
5 Correct 33 ms 14100 KB Output is correct
6 Correct 30 ms 12796 KB Output is correct
7 Correct 26 ms 12992 KB Output is correct
8 Correct 34 ms 13556 KB Output is correct
9 Correct 31 ms 13564 KB Output is correct
10 Correct 27 ms 13296 KB Output is correct
11 Correct 27 ms 13356 KB Output is correct
12 Correct 28 ms 13292 KB Output is correct
13 Correct 28 ms 13312 KB Output is correct
14 Correct 30 ms 13620 KB Output is correct
15 Correct 30 ms 13512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 12840 KB Output is correct
2 Correct 1 ms 516 KB Output is correct
3 Correct 29 ms 12336 KB Output is correct
4 Correct 32 ms 14144 KB Output is correct
5 Correct 33 ms 14100 KB Output is correct
6 Correct 30 ms 12796 KB Output is correct
7 Correct 26 ms 12992 KB Output is correct
8 Correct 34 ms 13556 KB Output is correct
9 Correct 31 ms 13564 KB Output is correct
10 Correct 27 ms 13296 KB Output is correct
11 Correct 27 ms 13356 KB Output is correct
12 Correct 28 ms 13292 KB Output is correct
13 Correct 28 ms 13312 KB Output is correct
14 Correct 30 ms 13620 KB Output is correct
15 Correct 30 ms 13512 KB Output is correct
16 Correct 27 ms 11088 KB Output is correct
17 Correct 23 ms 11192 KB Output is correct
18 Correct 25 ms 11240 KB Output is correct
19 Correct 24 ms 11240 KB Output is correct
20 Correct 27 ms 11896 KB Output is correct
21 Correct 26 ms 11548 KB Output is correct
22 Correct 30 ms 13560 KB Output is correct
23 Correct 25 ms 11372 KB Output is correct
24 Correct 26 ms 11292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 0 ms 520 KB Output is correct
3 Correct 0 ms 904 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 1 ms 780 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 776 KB Output is correct
12 Correct 2 ms 896 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
16 Correct 2 ms 908 KB Output is correct
17 Correct 2 ms 708 KB Output is correct
18 Correct 0 ms 768 KB Output is correct
19 Correct 1 ms 768 KB Output is correct
20 Correct 0 ms 776 KB Output is correct
21 Correct 1 ms 780 KB Output is correct
22 Correct 2 ms 776 KB Output is correct
23 Correct 1 ms 768 KB Output is correct
24 Correct 1 ms 776 KB Output is correct
25 Correct 1 ms 768 KB Output is correct
26 Correct 1 ms 776 KB Output is correct
27 Correct 1 ms 776 KB Output is correct
28 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 10904 KB Output is correct
2 Correct 28 ms 11508 KB Output is correct
3 Correct 0 ms 508 KB Output is correct
4 Correct 20 ms 10772 KB Output is correct
5 Correct 30 ms 12248 KB Output is correct
6 Correct 32 ms 12272 KB Output is correct
7 Incorrect 28 ms 11172 KB Wrong Answer [6]
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 10992 KB Output is correct
2 Correct 28 ms 11332 KB Output is correct
3 Correct 0 ms 516 KB Output is correct
4 Correct 22 ms 10720 KB Output is correct
5 Correct 32 ms 12208 KB Output is correct
6 Incorrect 28 ms 12156 KB Wrong Answer [6]
7 Halted 0 ms 0 KB -