제출 #287228

#제출 시각아이디문제언어결과실행 시간메모리
287228peti1234Toy Train (IOI17_train)C++17
100 / 100
447 ms1920 KiB
#include <bits/stdc++.h> using namespace std; const int c=5002; int n, m, db[c], si[c]; bool v[c], ki[c], sol[c], uj=1; vector<int> sz[c], inv[c], ans; queue<int> q; void solve() { while(q.size()>0) { int id=q.front(); q.pop(); if (!v[id]) { v[id]=1; for (int i=0; i<inv[id].size(); i++) { int x=inv[id][i]; db[x]++; if (!v[x] && (db[x]==si[x] || (db[x]==1 && ki[x]))) q.push(x); } } } } vector<int> who_wins(vector<int> f, vector<int> t, vector<int> x, vector<int> y) { n=f.size(), m=x.size(); for (int i=0; i<m; i++) { int a=x[i], b=y[i]; sz[a].push_back(b), inv[b].push_back(a); } for (int i=0; i<n; i++) si[i]=sz[i].size(), ki[i]=f[i]; while(uj) { uj=0; for (int i=0; i<n; i++) { v[i]=0, db[i]=0; if (t[i]) q.push(i); } solve(); for (int i=0; i<n; i++) { if (t[i] && (db[i]==0 || db[i]!=si[i] && ki[i]==0)) t[i]=0, uj=1; //if (i==0) cout << "valt " << t[i] << "\n"; } } for (int i=0; i<n; i++) { if (!v[i]) q.push(i); //if (!v[i]) cout << "ures " << i << endl; v[i]=0, ki[i]=1-ki[i], db[i]=0; } solve(); for (int i=0; i<n; i++) ans.push_back(!v[i]); return ans; }

컴파일 시 표준 에러 (stderr) 메시지

train.cpp: In function 'void solve()':
train.cpp:15:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |             for (int i=0; i<inv[id].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:38:51: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   38 |             if (t[i] && (db[i]==0 || db[i]!=si[i] && ki[i]==0)) t[i]=0, uj=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...