Submission #227770

#TimeUsernameProblemLanguageResultExecution timeMemory
227770AaronNaiduToy Train (IOI17_train)C++14
11 / 100
89 ms2048 KiB
#include <bits/stdc++.h> using namespace std; vector<int> a, r, f; vector<int> graph[6000]; vector<int> rgraph[6000]; vector<bool> visited; int givesAWin[6000]; pair<bool, int> inCycle[6000]; vector<int> DFSpath; vector<int> goodsInPath; queue<int> q; bool cycleTime(int node, int orig) { if (r[node]) { return true; } if (node == orig) { return false; } return cycleTime(f[node], orig); } void checkForCycle(int node, int starter, bool atStart) { // cout << "Checking " << node << "\n"; if (inCycle[node].first and (goodsInPath.size() == 0 or inCycle[node].second > goodsInPath[goodsInPath.size() - 1])) { //cout << "In the cycle\n"; for (int i = 0; i < DFSpath.size(); i++) { //cout << DFSpath[i] << " gives a win\n"; if (!givesAWin[DFSpath[i]]) { q.push(DFSpath[i]); } givesAWin[DFSpath[i]] = true; } //cout << "Leaving " << node << "\n"; return; } if (visited[node]) { //cout << "Already visited\n"; if (givesAWin[node]) { // cout << "Known to give a win\n"; for (auto i : DFSpath) { // cout << DFSpath[i] << " gives a win\n"; if (!givesAWin[i]) { q.push(i); } givesAWin[i] = true; } } // cout << "Leaving " << node << "\n"; return; } inCycle[node] = {true, DFSpath.size()}; if (r[node]) { // cout << node << " is a charging station\n"; goodsInPath.push_back(DFSpath.size()); } visited[node] = true; DFSpath.push_back(node); for (auto i : graph[node]) { checkForCycle(i, starter, atStart); } inCycle[node].first = false; DFSpath.pop_back(); if (r[node]) { goodsInPath.pop_back(); } // cout << "Leaving " << node << "\n"; } vector<int> who_wins(vector<int> la, vector<int> lr, vector<int> lu, vector<int> lv) { a = la; r = lr; for (int i = 0; i < lu.size(); i++) { graph[lu[i]].push_back(lv[i]); rgraph[lv[i]].push_back(lu[i]); } for (int i = 0; i < a.size(); i++) { f.push_back(-1); visited.push_back(false); } for (int i = 0; i < r.size(); i++) { if (!r[i]) { checkForCycle(i, i, true); } } while (!q.empty()) { int x = q.front(); q.pop(); for (auto i : rgraph[x]) { if (!givesAWin[i]) { givesAWin[i] = true; q.push(i); } } } vector<int> toRet; for (int i = 0; i < a.size(); i++) { toRet.push_back(!givesAWin[i]); } return toRet; }

Compilation message (stderr)

train.cpp: In function 'void checkForCycle(int, int, bool)':
train.cpp:31:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < DFSpath.size(); i++)
                         ~~^~~~~~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:88:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < lu.size(); i++)
                     ~~^~~~~~~~~~~
train.cpp:93:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); i++)
                     ~~^~~~~~~~~~
train.cpp:98:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < r.size(); i++)
                     ~~^~~~~~~~~~
train.cpp:122:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); 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...