Submission #212407

#TimeUsernameProblemLanguageResultExecution timeMemory
212407JustasZStray Cat (JOI20_stray)C++14
100 / 100
100 ms17004 KiB
#include "Anthony.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define x first #define y second #define all(a) a.begin(), a.end() #define sz(a) (int)a.size() #define rd() abs((int)rng()) typedef long long ll; typedef long double ld; typedef pair<int, int>pii; const int maxn = 2e4 + 100; const int mod = 1e9 + 7; namespace { int n, m, A, B; vector<int>U, V, label; vector<pii>adj[maxn]; void solve1() { queue<int>Q; vector<int>dist(n, mod); dist[0] = 0; Q.push(0); while (sz(Q)) { int v = Q.front(); Q.pop(); for (pii to : adj[v]) { if (dist[to.x] > dist[v] + 1) { dist[to.x] = dist[v] + 1; Q.push(to.x); } } } for (int i = 0; i < m; i++) { label[i] = min(dist[V[i]], dist[U[i]]) % 3; } } string s = "010011"; void dfs(int v, int p, int prev_label) { for (pii to : adj[v]) { if (to.x != p) { if (sz(adj[v]) > 2) { int new_label = (s[prev_label] - '0') ^ 1; label[to.y] = new_label; dfs(to.x, v, new_label); } else { int new_label = (prev_label + 1) % 6; label[to.y] = (s[new_label] - '0'); dfs(to.x, v, new_label); } } } } void solve2() { dfs(0, 0, 0); } vector<int> solve(int N, int M, int AA, int BB, vector<int>UU, vector<int>VV) { n = N, m = M, A = AA, B = BB; U = UU, V = VV; label.resize(m); for (int i = 0; i < m; i++) { adj[U[i]].pb({V[i], i}); adj[V[i]].pb({U[i], i}); } if (A >= 3) { solve1(); } else { solve2(); } return label; } } // namespace vector<int>Mark(int N, int M, int A, int B, vector<int>U, vector<int>V) { return solve(N, M, A, B, U, V); }
#include "Catherine.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define x first #define y second #define all(a) a.begin(), a.end() #define sz(a) (int)a.size() #define rd() abs((int)rng()) typedef long long ll; typedef long double ld; typedef pair<int, int>pii; const int maxn = 2e4 + 100; const int mod = 1e9 + 7; namespace { int A, B; string cur; vector<int>moves; bool flag = false; int go(vector<int>y) { int cnt = y[0] + y[1]; if (flag) { if (cnt == 1) { moves.pb((y[0] > 0 ? 0 : 1)); } else { moves.pb(moves.back() ^ 1); } } else { if (cnt == 0) { flag = true; moves.pb(moves.back()); return -1; } if (cnt == 1) { if (!sz(moves)) { flag = true; moves.pb((y[0] > 0 ? 0 : 1)); } else { if (sz(moves) < 4) { moves.pb((y[0] > 0 ? 0 : 1)); } else { string t; for (int move : moves) { t += (move + '0'); } t += (y[0] > 0 ? '0' : '1'); string s = "110010"; bool chk = false; for (int rot = 0; rot < 6; rot++) { if (s.substr(0, 5) == t) { chk = true; } rotate(s.begin(), s.begin() + 1, s.end()); } flag = true; if (chk) { moves.pb((y[0] > 0 ? 0 : 1)); } else { moves.pb(moves.back()); return -1; } } } } else { if (!sz(moves)) { if (cnt == 2) { moves.pb((y[0] > 0 ? 0 : 1)); moves.pb((y[1] > 0 ? 1 : 0)); } else { flag = true; moves.pb((y[0] == 1 ? 0 : 1)); } } else { flag = true; if (!y[0] || !y[1]) { flag = true; moves.pb(moves.back()); return -1; } else { flag = true; moves.pb(moves.back() ^ 1); } } } } return moves.back(); } } // namespace void Init(int A, int B) { ::A = A; ::B = B; } int Move(vector<int>y) { if (A >= 3) { for (int i = 0; i < 3; i++) { if (y[i] > 0 && y[(i + 1) % 3] > 0) { return i; } } for (int i = 0; i < 3; i++) { if (y[i] > 0) { return i; } } } else { return go(y); } }

Compilation message (stderr)

Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:113:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...