#include <iostream>
#include <vector>
#include <cstdio>
#include <cassert>
#include <algorithm>
using namespace std;
bool isSubtask1(vector<int>& u, vector<int>& v) {
int m = u.size();
for(int i=0; i<m; i++)
if (v[i]!=u[i] && v[i]!=u[i]+1) return false;
return true;
}
vector<int> subtask1(vector<int>& a, vector<int>& r, vector<int>& u, vector<int>& v) {
int n = a.size(), m = u.size();
vector<int> ans(n,0);
vector<vector<int>> adj(n,vector<int>(n,0));
for(int i=0; i<m; i++) adj[u[i]][v[i]] = 1;
// for(int i=0; i<n; i++) {
// for(int j=0; j<n; j++)
// cout << adj[i][j] << " ";
// cout << endl;
// }
// return ans;
ans[n-1]=r[n-1];
for(int i=n-2; i>=0; i--)
if (a[i]) {ans[i] = adj[i][i] && r[i] || adj[i][i+1] && ans[i+1];}
else {ans[i] = (adj[i][i]==0 || r[i]) && (adj[i][i+1]==0 || ans[i+1]);}
return ans;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
vector<int> res(a.size());
int n = a.size(), m = u.size();
vector<vector<int>> adj(n);
for(int i=0; i<m; i++) adj[u[i]].push_back(v[i]);
for(int i=0; i<n; i++) sort(adj[i].begin(),adj[i].end());
// if (isSubtask1(u,v))
return subtask1(a,r,u,v);
for(int i=0; i<n; i++) {
cout << i << ": ";
for (const int elem: adj[i])
cout << elem << " ";
cout << endl;
}
for(int i = 0; i < n; i++)
res[i] = i % 2;
return res;
}
Compilation message
train.cpp: In function 'std::vector<int> subtask1(std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
train.cpp:29:39: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
29 | if (a[i]) {ans[i] = adj[i][i] && r[i] || adj[i][i+1] && ans[i+1];}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
98900 KB |
Output is correct |
2 |
Correct |
41 ms |
98916 KB |
Output is correct |
3 |
Correct |
37 ms |
98900 KB |
Output is correct |
4 |
Correct |
36 ms |
98908 KB |
Output is correct |
5 |
Correct |
36 ms |
98908 KB |
Output is correct |
6 |
Correct |
43 ms |
98904 KB |
Output is correct |
7 |
Correct |
37 ms |
99020 KB |
Output is correct |
8 |
Correct |
37 ms |
98824 KB |
Output is correct |
9 |
Correct |
38 ms |
98908 KB |
Output is correct |
10 |
Correct |
40 ms |
98992 KB |
Output is correct |
11 |
Correct |
37 ms |
98896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
3rd lines differ - on the 8th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
99412 KB |
Output is correct |
2 |
Correct |
43 ms |
99408 KB |
Output is correct |
3 |
Correct |
40 ms |
99256 KB |
Output is correct |
4 |
Incorrect |
41 ms |
99412 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
99088 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
99412 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
98900 KB |
Output is correct |
2 |
Correct |
41 ms |
98916 KB |
Output is correct |
3 |
Correct |
37 ms |
98900 KB |
Output is correct |
4 |
Correct |
36 ms |
98908 KB |
Output is correct |
5 |
Correct |
36 ms |
98908 KB |
Output is correct |
6 |
Correct |
43 ms |
98904 KB |
Output is correct |
7 |
Correct |
37 ms |
99020 KB |
Output is correct |
8 |
Correct |
37 ms |
98824 KB |
Output is correct |
9 |
Correct |
38 ms |
98908 KB |
Output is correct |
10 |
Correct |
40 ms |
98992 KB |
Output is correct |
11 |
Correct |
37 ms |
98896 KB |
Output is correct |
12 |
Incorrect |
0 ms |
344 KB |
3rd lines differ - on the 8th token, expected: '0', found: '1' |
13 |
Halted |
0 ms |
0 KB |
- |