/*
Author of all code: Pedro BIGMAN Dias
Last edit: 15/02/2021
*/
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 500000000LL
#define EPS 0.00000001
#define pi 3.14159
#define VV(vvvv,NNNN,xxxx); REP(i,0,NNNN) {vvvv.pb(xxxx);}
ll mod=1000000007LL;
template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}
template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}}
unordered_map<ll,ll> m; ll N,M; vector<ll> p3; vector<vector<ll> > adj; ll typ; vector<ll> a,r;
void Clarify(ll s)
{
ll e=s%N; ll mai=s/N;
cout<<"Last station: "<<e<<", visited stations before last charge: ";
REP(i,0,N) {if((mai/p3[i])%3==1) {cout<<i<<" ";}}
cout<<", visited stations after last charge: ";
REP(i,0,N) {if((mai/p3[i])%3==2) {cout<<i<<" ";}}
cout<<endl;
}
void f(ll s)
{
if(m.find(s)!=m.end()) {return;}
ll e=s%N; ll mai=s/N;
vector<ll> nxt;
REP(i,0,adj[e].size())
{
typ=(mai/p3[adj[e][i]])%3;
if(typ==2 && a[e]==0) {m[s]=0; return;}
else if(typ==1 && a[e]==1) {m[s]=1; return;}
else if(typ==0)
{
if(r[adj[e][i]]==0) {nxt.pb((mai+2*p3[adj[e][i]])*N+adj[e][i]);}
else
{
ll newmai=mai + p3[adj[e][i]];
REP(j,0,N)
{
if((mai/p3[j])%3==2) {newmai-=p3[j];}
}
nxt.pb(newmai*N+adj[e][i]);
}
}
}
REP(i,0,nxt.size())
{
f(nxt[i]);
if(a[e]==m[nxt[i]]) {m[s]=m[nxt[i]]; return;}
}
m[s]=1-a[e]; return;
}
vector<int> who_wins(vector<int> aa, vector<int> rr, vector<int> u, vector<int> v)
{
a=aa; r=rr;
N=a.size(); M=u.size(); REP(i,0,N) {adj.pb({});}
REP(i,0,M) {adj[u[i]].pb(v[i]);}
ll curpow=1; REP(i,0,16) {p3.pb(curpow); curpow*=3;}
vector<ll> ans;
REP(i,0,N) {if(r[i]==0) {f(2*p3[i]*N+i); ans.pb(m[2*p3[i]*N+i]);} else {f(p3[i]*N+i); ans.pb(m[p3[i]*N+i]);}}
return ans;
}
Compilation message
train.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
5 | #pragma GCC optimization ("O3")
|
train.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
6 | #pragma GCC optimization ("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1420 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
296 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
288 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
2160 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
1768 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
2160 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1420 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |