이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
#include "train.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
vector<vi> adjList(5005, vi());
vector<bool> gotov(5005, false), t(5005, false);
int n;
vi operator-(vi a, vi b){
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vi res; int j = 0;
for (int i = 0; i < a.size(); i++){
while(j < b.size() && b[j] < a[i])
j++;
if (j == b.size() || b[j] > a[i])
res.push_back(a[i]);
}
return res;
}
int deg[5005];
bool vis[5005];
vi f(bool type, vi x){
for (int i = 0; i < n; i++)
vis[i] = deg[i] = 0;
for (int i = 0; i < n; i++){
if (gotov[i])
continue;
for (int j = 0; j < adjList[i].size(); j++){
int curr = adjList[i][j];
if (!gotov[curr])
deg[curr]++;
}
}
queue<int> q;
for (int i = 0; i < x.size(); i++)
vis[x[i]] = true, q.push(x[i]);
while(!q.empty()){
int curr = q.front();
q.pop();
for (int i = 0; i < adjList[curr].size(); i++){
int k = adjList[curr][i];
if (gotov[k] || vis[k])
continue;
if (t[k] == type)
vis[k] = 1, q.push(k);
else{
deg[k]--;
if (!deg[k])
vis[k] = 1, q.push(k);
}
}
}
vi res;
for (int i = 0; i < n; i++){
if (!gotov[i] && vis[i])
res.push_back(i);
}
return res;
}
vi who_wins(vi a, vi r, vi u, vi v){
n = a.size(); int m = u.size();
for (int i = 0; i < m; i++)
adjList[v[i]].push_back(u[i]);
vi graph;
for (int i = 0; i < n; i++)
graph.push_back(i), t[i] = a[i];
while(!graph.empty()){
vi f_a, f_b;
for (int i = 0; i < graph.size(); i++)
if (r[graph[i]])
f_a.push_back(i);
f_a = f(1, f_a); f_b = f(0, graph - f_a);
if (!f_b.size())
break;
for (int i = 0; i < f_b.size(); i++)
gotov[f_b[i]] = true;
graph = graph - f_b;
}
vi res(n, 0);
for (int i = 0; i < graph.size(); i++)
res[graph[i]] = true;
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
train.cpp: In function 'vi operator-(vi, vi)':
train.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < a.size(); i++){
| ~~^~~~~~~~~~
train.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | while(j < b.size() && b[j] < a[i])
| ~~^~~~~~~~~~
train.cpp:26:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | if (j == b.size() || b[j] > a[i])
| ~~^~~~~~~~~~~
train.cpp: In function 'vi f(bool, vi)':
train.cpp:38:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
38 | vis[i] = deg[i] = 0;
| ~~~~~~~^~~
train.cpp:43:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int j = 0; j < adjList[i].size(); j++){
| ~~^~~~~~~~~~~~~~~~~~~
train.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int i = 0; i < x.size(); i++)
| ~~^~~~~~~~~~
train.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i = 0; i < adjList[curr].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~~~~~
train.cpp: In function 'vi who_wins(vi, vi, vi, vi)':
train.cpp:91:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for (int i = 0; i < graph.size(); i++)
| ~~^~~~~~~~~~~~~~
train.cpp:100:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for (int i = 0; i < f_b.size(); i++)
| ~~^~~~~~~~~~~~
train.cpp:107:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for (int i = 0; i < graph.size(); i++)
| ~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |