# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
416605 |
2021-06-02T16:56:38 Z |
yanire |
Toy Train (IOI17_train) |
C++11 |
|
8 ms |
1100 KB |
#include <bits/stdc++.h>
using namespace std;
#include "train.h"
#define fin(i,s,n) for(auto i = s; i < n; ++i)
#define fine(i,s,n) for(auto i = s; i <= n; ++i)
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define chkmin(a,b) a = min(a,b)
#define chkmax(a,b) a = max(a,b)
using stdvec = vector<int>;
using ii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vii = vector<ii>;
#define sz(a) int((a).size())
const int maxn = 5005;
vi G[maxn],T[maxn],g[maxn];
bool vis[maxn];
int id[maxn],c[maxn],p[maxn];
vi lst;
void dfs(int u) {
if(vis[u]) return;
vis[u] = 1;
for(int v : G[u]) dfs(v);
lst.pb(u);
}
void mark(int u, int cid) {
if(!vis[u]) return;
vis[u] = 0,id[u] = cid;
for(int v : T[u]) mark(v,cid);
}
bool bdfs(int u) {
// cout << "bdfs("<<u<<") called\n";
if(c[u]) return /*cout << "cu 1\n",*/1;
if(vis[u]) return /*cout << "already been here\n",*/0;
vis[u] = 1;
int cnt = 0;
for(int v : g[u]) {
if(u==v)return /*cout<<"self loop, bdfs("<<u<<") returns 0\n",*/0;
cnt += bdfs(v);
}
// cout << "at "<<u<<",cnt="<<cnt<<",sz(g)="<<sz(g[u])<<endl;
if(cnt==sz(g[u])) return 1;
return 0;
}
vi who_wins(vi a, vi r, vi u, vi v) {
int n = a.size(),m = u.size();
vi lp(n,0),nxt(n,0);
fin(i,0,m) {
if(u[i]==v[i]) lp[u[i]]=1;
else nxt[u[i]] = 1;
}
fin(i,0,n) p[i]=a[i],c[i]=r[i];
vi dp(n+1,0);
for(int i = n-1; ~i; --i) {
if(p[i]) {
if((c[i]&&lp[i]) || (nxt[i]&&dp[i+1])) dp[i] = 1;
} else {
if(c[i]&&lp[i]&&(!nxt[i])) dp[i] = 1;
if(nxt[i]&&!lp[i]&&dp[i+1]) dp[i] = 1;
if(lp[i]&&nxt[i]&&c[i]&&dp[i+1]) dp[i] = 1;
}
}
dp.pop_back();
return dp;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
844 KB |
Output is correct |
2 |
Correct |
4 ms |
972 KB |
Output is correct |
3 |
Correct |
4 ms |
972 KB |
Output is correct |
4 |
Correct |
4 ms |
920 KB |
Output is correct |
5 |
Correct |
4 ms |
916 KB |
Output is correct |
6 |
Correct |
6 ms |
920 KB |
Output is correct |
7 |
Correct |
4 ms |
972 KB |
Output is correct |
8 |
Correct |
5 ms |
920 KB |
Output is correct |
9 |
Correct |
5 ms |
972 KB |
Output is correct |
10 |
Correct |
4 ms |
972 KB |
Output is correct |
11 |
Correct |
4 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
588 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1100 KB |
Output is correct |
2 |
Correct |
8 ms |
1100 KB |
Output is correct |
3 |
Correct |
6 ms |
1100 KB |
Output is correct |
4 |
Incorrect |
6 ms |
1100 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 |
5 ms |
972 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
1100 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
844 KB |
Output is correct |
2 |
Correct |
4 ms |
972 KB |
Output is correct |
3 |
Correct |
4 ms |
972 KB |
Output is correct |
4 |
Correct |
4 ms |
920 KB |
Output is correct |
5 |
Correct |
4 ms |
916 KB |
Output is correct |
6 |
Correct |
6 ms |
920 KB |
Output is correct |
7 |
Correct |
4 ms |
972 KB |
Output is correct |
8 |
Correct |
5 ms |
920 KB |
Output is correct |
9 |
Correct |
5 ms |
972 KB |
Output is correct |
10 |
Correct |
4 ms |
972 KB |
Output is correct |
11 |
Correct |
4 ms |
972 KB |
Output is correct |
12 |
Incorrect |
1 ms |
588 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
13 |
Halted |
0 ms |
0 KB |
- |