# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
390032 |
2021-04-15T06:05:04 Z |
Keshi |
Toy Train (IOI17_train) |
C++17 |
|
47 ms |
31096 KB |
//In the name of God
#include <bits/stdc++.h>
#include "train.h"
using namespace std;
typedef int ll;
typedef pair<ll, ll> pll;
const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
ll n, m, c[maxn], t;
bool del[maxn], ok[maxn], vis[maxn], w[maxn], okk[maxn];
bool sub1 = 1, sub3 = 1, sub4 = 1;
vector<ll> vec, g[maxn], gp[maxn], com[maxn];
void dfs(ll v){
vis[v] = 1;
if(del[v]) return;
for(ll u : g[v]){
if(!vis[u]) dfs(u);
}
vec.pb(v);
}
void sfd(ll v){
vis[v] = 1;
if(del[v]) return;
for(ll u : gp[v]){
if(!vis[u]) sfd(u);
}
c[v] = t;
com[t].pb(v);
if(ok[v]) okk[t] = 1;
}
bool solve(ll v){
if(w[v]) return 1;
vis[v] = 1;
for(ll u : g[v]){
if(!vis[u] && solve(u)) return 1;
}
return 0;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> v, vector<int> u){
n = Sz(a);
m = Sz(v);
for(ll i = 0; i < m; i++){
if(u[i] != v[i] && u[i] != v[i] + 1) sub1 = 0;
g[v[i]].pb(u[i]);
gp[u[i]].pb(v[i]);
}
vector<int> res(n);
for(ll i = 0; i < n; i++){
if(a[i]) sub4 = 0;
else sub3 = 0;
}
for(ll i = 0; i < n; i++){
if(sub3) ok[i] = r[i];
else ok[i] = 1;
if(sub4) del[i] = r[i];
}
for(ll i = 0; i < n; i++){
if(!vis[i]) dfs(i);
}
fill(vis, vis + n, 0);
reverse(all(vec));
for(ll i = 0; i < n; i++){
if(!vis[i]){
sfd(i);
t++;
}
}
for(ll i = 0; i < n; i++){
if(del[i]) continue;
for(ll j : g[i]){
if(i == j && ok[i]) w[i] = 1;
}
if(okk[c[i]]) w[i] = 1;
}
for(ll i = 0; i < n; i++){
fill(vis, vis + n, 0);
res[i] = solve(i);
if(sub4) res[i] ^= 1;
}
if(!sub3) cout << 1/0;
return res;
}
Compilation message
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:96:23: warning: division by zero [-Wdiv-by-zero]
96 | if(!sub3) cout << 1/0;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
40 ms |
30856 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
22 ms |
29004 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
15616 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
45 ms |
30400 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
47 ms |
31096 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
40 ms |
30856 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |