답안 #495331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495331 2021-12-18T12:57:47 Z PedroBigMan 장난감 기차 (IOI17_train) C++14
0 / 100
7 ms 2268 KB
/*
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 long long 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; ll e; ll mai; vector<vector<ll> > adj; ll typ; vector<ll> a,r;

void f(ll s)
{
	if(m.find(s)!=m.end()) {return;}
	e=s%N; 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) 
{
	REP(i,0,aa.size()) {a.pb(aa[i]); r.pb(rr[i]);}
	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<int> 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")
      |
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 1596 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 8th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 2268 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1980 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 2260 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 1596 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -