#include "train.h"
#include <bits/stdc++.h>
using namespace std;
const int N=5010;
vector<int> g[N];
int d[N][N];
void bfs(int root){
queue<int> q;
q.push(root);
while (q.size()){
int u=q.front();
q.pop();
for (int v:g[u]) if (!d[root][v]){
d[root][v]=1;
q.push(v);
}
}
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int n=a.size(), m=u.size();
bool sub1=1;
for (int i=0; i<m; ++i) sub1&=u[i]==v[i] || u[i]+1==v[i];
if (sub1){
vector<int> ans(n), cyc(n);
for (int i=0; i<m; ++i) if (u[i]==v[i]) cyc[u[i]]|=1; else cyc[u[i]]|=2;
for (int i=n-1; i>=0; --i){
if (cyc[i]==1){
ans[i]=r[i];
}else if (cyc[i]==2){
ans[i]=ans[i+1];
}else{
if (a[i]) ans[i]=r[i] || ans[i+1];
else ans[i]=r[i] && ans[i+1];
}
}
return ans;
}
for (int i=0; i<m; ++i) g[u[i]].push_back(v[i]);
for (int i=0; i<n; ++i) bfs(i);
vector<int> ans(n);
for (int i=0; i<n; ++i){
for (int j=0; j<n; ++j) if (a[j]) ans[i]|=d[i][j] && d[j][j];
}
for (int i=0; i<n; ++i) g[i].clear();
for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) d[i][j]=0;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
648 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
648 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
226 ms |
99152 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
624 ms |
99012 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
722 ms |
99176 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
648 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
648 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Incorrect |
1 ms |
600 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
13 |
Halted |
0 ms |
0 KB |
- |