Submission #781223

#TimeUsernameProblemLanguageResultExecution timeMemory
781223GusterGoose27Toy Train (IOI17_train)C++17
100 / 100
349 ms1860 KiB
#include "train.h" #include <bits/stdc++.h> const int MAXN = 5005; using namespace std; vector<int> edges[MAXN]; vector<int> rev[MAXN]; int deg[MAXN]; bool owner[MAXN]; // 0 b, 1 a vector<int> ans; int n, m; void activate(int cur) { if (ans[cur]) return; // r[i] assert(!ans[cur]); ans[cur] = 1; for (int v: rev[cur]) { deg[v]++; if ((deg[v] == 1 && owner[v]) || (deg[v] == edges[v].size() && !owner[v])) activate(v); } } void deactivate(int cur) { assert(ans[cur]); ans[cur] = 0; for (int v: rev[cur]) { deg[v]--; if ((deg[v] == 0 && owner[v]) || (deg[v] == edges[v].size()-1 && !owner[v])) deactivate(v); } } vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { n = a.size(); m = u.size(); for (int i = 0; i < n; i++) owner[i] = a[i]; for (int i = 0; i < m; i++) { edges[u[i]].push_back(v[i]); rev[v[i]].push_back(u[i]); } bool f = 1; while (f) { f = 0; fill(deg, deg+n, 0); ans = vector<int>(n, 0); for (int i = 0; i < n; i++) { if (r[i]) activate(i); } for (int i = 0; i < n; i++) { if (ans[i] && ((deg[i] == 0 && owner[i]) || (deg[i] < edges[i].size() && !owner[i]))) { r[i] = 0; f = 1; break; } } } return ans; }

Compilation message (stderr)

train.cpp: In function 'void activate(int)':
train.cpp:20:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   if ((deg[v] == 1 && owner[v]) || (deg[v] == edges[v].size() && !owner[v])) activate(v);
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~~
train.cpp: In function 'void deactivate(int)':
train.cpp:29:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   if ((deg[v] == 0 && owner[v]) || (deg[v] == edges[v].size()-1 && !owner[v])) deactivate(v);
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:50:56: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |    if (ans[i] && ((deg[i] == 0 && owner[i]) || (deg[i] < edges[i].size() && !owner[i]))) {
      |                                                 ~~~~~~~^~~~~~~~~~~~~~~~~
#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...