#include <bits/stdc++.h>
#include "train.h"
#define ent '\n'
#define f first
#define s second
//#define int long long
using namespace std;
typedef long long ll;
const int maxn = 5e3 + 12;
const int mod = 1e9 + 7;
vector<int> g[maxn], rg[maxn];
bool won[maxn], del[maxn];
int out[maxn];
int n, m;
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> U, vector<int> V){
n = a.size(), m = U.size();
vector<int> ans(n);
for(int i=0;i<m;i++){
g[U[i]].push_back(V[i]);
rg[V[i]].push_back(U[i]);
}
for(int mask = 1;mask < (1 << n);mask++){
for(int i=0;i<n;i++){
out[i] = g[i].size();
won[i] = 0;
}
queue<int> q;
for(int i=0;i<n;i++){
won[i] = 0;
if((mask & (1 << i)) && r[i] == 1){
won[i] = 1;
q.push(i);
}
}
while(q.size()){
int v = q.front();
q.pop();
for(int to:rg[v]){
if(a[to] && !won[to]){
won[to] = 1;
q.push(to);
}
if(!a[to] && !won[to]){
out[to]--;
if(out[to] == 0){
won[to] = 1;
q.push(to);
}
}
}
}
bool fg = 1;
for(int i=0;i<n;i++){
if((mask & (1 << i))){
if(!r[i]) fg = 0;
bool ok = 1 - a[i];
for(int to:g[i]){
if(a[i]) ok |= won[to];
else ok &= won[to];
}
fg &= ok;
}
}
if(fg){
for(int i=0;i<n;i++){
ans[i] |= won[i];
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1112 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
604 KB |
Output is correct |
2 |
Correct |
6 ms |
604 KB |
Output is correct |
3 |
Correct |
6 ms |
604 KB |
Output is correct |
4 |
Correct |
7 ms |
604 KB |
Output is correct |
5 |
Correct |
6 ms |
604 KB |
Output is correct |
6 |
Correct |
9 ms |
684 KB |
Output is correct |
7 |
Correct |
7 ms |
604 KB |
Output is correct |
8 |
Correct |
8 ms |
604 KB |
Output is correct |
9 |
Correct |
8 ms |
684 KB |
Output is correct |
10 |
Correct |
7 ms |
680 KB |
Output is correct |
11 |
Correct |
9 ms |
604 KB |
Output is correct |
12 |
Correct |
7 ms |
680 KB |
Output is correct |
13 |
Correct |
6 ms |
604 KB |
Output is correct |
14 |
Correct |
5 ms |
688 KB |
Output is correct |
15 |
Correct |
5 ms |
604 KB |
Output is correct |
16 |
Correct |
6 ms |
604 KB |
Output is correct |
17 |
Correct |
5 ms |
604 KB |
Output is correct |
18 |
Correct |
6 ms |
856 KB |
Output is correct |
19 |
Correct |
6 ms |
604 KB |
Output is correct |
20 |
Correct |
6 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1628 KB |
Output is correct |
2 |
Correct |
22 ms |
1628 KB |
Output is correct |
3 |
Correct |
23 ms |
1880 KB |
Output is correct |
4 |
Incorrect |
40 ms |
1680 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1372 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
1596 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1112 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |