Submission #116999

#TimeUsernameProblemLanguageResultExecution timeMemory
116999zubecToy Train (IOI17_train)C++14
100 / 100
948 ms1652 KiB
#include "train.h" #include <bits/stdc++.h> using namespace std; vector <int> gg[5010]; int kol[5010]; bool used[5010]; int n, clr[5010], chrg[5010]; bool delt[5010]; vector <pair<int, int> > rebr; queue <int> q; void cler(){ for (int i = 0; i < n; i++){ used[i] = 0; kol[i] = 0; } for (int i = 0; i < rebr.size(); i++){ int u = rebr[i].first, v = rebr[i].second; if (!delt[u] && !delt[v]) ++kol[u]; } } void f(int c){ cler(); while(!q.empty()){ int v = q.front(); q.pop(); if (used[v]) continue; used[v] = 1; for (int j = 0; j < gg[v].size(); j++){ int to = gg[v][j]; if (delt[to]) continue; --kol[to]; if (used[to]) continue; if (clr[to] == c){ q.push(to); } else if (kol[to] == 0){ q.push(to); } } } } vector <int> vec; bool solve(){ for (int i = 0; i < vec.size(); i++){ if (chrg[vec[i]]) q.push(vec[i]); } f(0); for (int i = 0; i < vec.size(); i++){ if (!used[vec[i]]) q.push(vec[i]); } f(1); bool bb = 0; for (int i = vec.size()-1; i >= 0; i--){ if (used[vec[i]]){ bb = 1; delt[vec[i]] = 1; swap(vec[i], vec.back()); vec.pop_back(); } } return bb; } std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) { vector <int> ansvec; rebr.clear(); n = a.size(); for (int i = 0; i < n; i++){ gg[i].clear(); delt[i] = 0; clr[i] = a[i]^1; chrg[i] = r[i]; } for (int i = 0; i < u.size(); i++){ gg[v[i]].push_back(u[i]); rebr.push_back({u[i], v[i]}); } for (int i = 0; i < n; i++){ vec.push_back(i); } while(solve()){ } ansvec.resize(n); for (int i = 0; i < vec.size(); i++){ ansvec[vec[i]] = 1; } return ansvec; } /** 2 4 0 1 1 0 0 0 0 1 1 0 1 1 */

Compilation message (stderr)

train.cpp: In function 'void cler()':
train.cpp:24:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < rebr.size(); i++){
                     ~~^~~~~~~~~~~~~
train.cpp: In function 'void f(int)':
train.cpp:40:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < gg[v].size(); j++){
                         ~~^~~~~~~~~~~~~~
train.cpp: In function 'bool solve()':
train.cpp:59:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++){
                     ~~^~~~~~~~~~~~
train.cpp:64:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.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:91:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < u.size(); i++){
                     ~~^~~~~~~~~~
train.cpp:103:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.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...