Submission #74061

#TimeUsernameProblemLanguageResultExecution timeMemory
74061Bruteforceman장난감 기차 (IOI17_train)C++11
28 / 100
356 ms7220 KiB
#include "train.h" #include "bits/stdc++.h" using namespace std; vector <int> g[5005]; vector <int> trans[5005]; int own[5005]; int charge[5005]; int n; int m; int out[5005]; bool take[5005]; bool del[5005]; vector <int> Fa(vector <int> v) { for(int i = 0; i < n; i++) { out[i] = 0; take[i] = false; } queue <int> q; for(auto i : v) { q.push(i); take[i] = true; } while(!q.empty()) { int i = q.front(); q.pop(); for(auto j : trans[i]) { if(del[j]) continue; out[j] += 1; if(!take[j] && own[j] == 1) { q.push(j); take[j] = true; } if(!take[j] && out[j] == g[j].size() && own[j] == 0) { q.push(j); take[j] = true; } } } vector <int> ans; for(int i = 0; i < n; i++) { if(take[i]) { ans.emplace_back(i); } } return ans; } vector <int> Fb(vector <int> v) { for(int i = 0; i < n; i++) { out[i] = 0; take[i] = false; } queue <int> q; for(auto i : v) { q.push(i); take[i] = true; } while(!q.empty()) { int i = q.front(); q.pop(); for(auto j : trans[i]) { if(del[j]) continue; out[j] += 1; if(!take[j] && own[j] == 0) { q.push(j); take[j] = true; } if(!take[j] && out[j] == g[j].size() && own[j] == 1) { q.push(j); take[j] = true; } } } vector <int> ans; for(int i = 0; i < n; i++) { if(take[i]) { ans.emplace_back(i); } } return ans; } std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) { vector <int> ans; n = a.size(); m = u.size(); ans.resize(n); for(int i = 0; i < n; i++) { own[i] = a[i]; charge[i] = r[i]; del[i] = false; } for(int i = 0; i < m; i++) { int p = u[i]; int q = v[i]; g[p].emplace_back(q); trans[q].emplace_back(p); } while(true) { vector <int> station; for(int i = 0; i < n; i++) { if(charge[i] && !del[i]) { station.emplace_back(i); } } vector <int> P = Fa(station); vector <int> Q; for(int i = 0; i < n; i++) { take[i] = false; } for(auto i : P) { take[i] = true; } for(int i = 0; i < n; i++) { if(!take[i] && !del[i]) { Q.emplace_back(i); } } if(Q.empty()) { for(auto i : P) { ans[i] = 1; } break; } vector <int> X = Fb(Q); for(auto i : X) { ans[i] = 0; del[i] = true; } } return ans; }

Compilation message (stderr)

train.cpp: In function 'std::vector<int> Fa(std::vector<int>)':
train.cpp:36:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(!take[j] && out[j] == g[j].size() && own[j] == 0) {
                   ~~~~~~~^~~~~~~~~~~~~~
train.cpp: In function 'std::vector<int> Fb(std::vector<int>)':
train.cpp:70:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(!take[j] && out[j] == g[j].size() && own[j] == 1) {
                   ~~~~~~~^~~~~~~~~~~~~~
#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...