Submission #216323

#TimeUsernameProblemLanguageResultExecution timeMemory
216323model_codeStray Cat (JOI20_stray)C++17
100 / 100
77 ms16380 KiB
#include "Anthony.h" #include <queue> #include <utility> #include <vector> namespace { using std::vector; } // namespace std::vector<int> Mark(int N, int M, int A, int B, std::vector<int> U, std::vector<int> V) { vector<vector<int>> G(N); for (int i = 0; i < M; ++i) { G[U[i]].push_back(i); G[V[i]].push_back(i); } std::queue<int> que; vector<int> dist(N, N); vector<int> colors(N, -1); dist[0] = 0; que.push(0); for (; !que.empty(); ) { const int u = que.front(); que.pop(); for (const int i : G[u]) { const int v = U[i] ^ V[i] ^ u; if (dist[v] > dist[u] + 1) { dist[v] = dist[u] + 1; que.push(v); if (A == 2) { if (u == 0) { colors[v] = 0; } else if (G[u].size() >= 3) { colors[v] = ("010011"[colors[u]] == '0') ? 1 : 0; } else { colors[v] = (colors[u] + 1) % 6; } } } } } vector<int> x(M, -1); for (int i = 0; i < M; ++i) { int u = U[i], v = V[i]; if (dist[u] > dist[v]) { std::swap(u, v); } if (A == 2) { x[i] = "010011"[colors[v]] - '0'; } else { x[i] = dist[u] % 3; } } 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...