답안 #618122

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
618122 2022-08-01T23:35:19 Z StrawHatWess 장난감 기차 (IOI17_train) C++17
0 / 100
22 ms 59948 KB
#include "train.h"

#include <bits/stdc++.h>
using namespace std; 

typedef vector<int>vi; 
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)

#define FOR(i,a,b) for(int i=a; i<b; i++)

//------------------------------

const int MX=5005; 

int N,M;
vi a,r,adj[MX];

int memo2[15][1<<15][15][2];
int solve2(int s, int m, int u, int fuel){
	if(r[u]) fuel=1; 

	int &ind=memo2[s][m][u][fuel]; 
	if(ind!=-1) return ind; 

	int ans=1-a[u]; 
	for(int v: adj[u]){
		if(v==s){
			if(a[u]) ans|=fuel;
			else ans&=fuel;
		}
		else if(!(m>>v)&1){
			if(a[u]) ans|=solve2(s,((m)|(1<<v)),v,fuel); 
			else ans&=solve2(s,((m)|(1<<v)),v,fuel); 
		}
	}
	return ind=ans; 
}


int memo[1<<15][15];  
int solve(int m, int u){
	if(solve2(u,m,u,0)) return 1; 

	int &ind=memo[m][u]; 
	if(ind!=-1) return ind; 

	int ans=1-a[u]; 
	for(int v: adj[u]) if(!((m>>v)&1)){
		int val=solve( ((m)|(1<<v)), v);
		if(a[u]){
			ans|=val; 
		}
		else{
			ans&=val;
		}
	}

	return ind=ans; 
}

vi who_wins(vi a, vi r, vi U, vi V) {
	N=sz(a); M=sz(U); 
	::a=a; ::r=r;

	FOR(i,0,M){
		int u=U[i], v=V[i];
		adj[u].pb(v); 
	}

	if(N<=15){
		memset(memo,-1,sizeof(memo));  memset(memo2,-1,sizeof(memo2)); 
		vi ans(N); 
		FOR(i,0,N){
			ans[i]=solve(1<<i,i); 
		}
		return ans; 
	}

	return vi(N,0); 
}


/*

2 4
0 1
1 0
0 0
0 1
1 0
1 1


*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 852 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 59948 KB Output is correct
2 Incorrect 22 ms 59948 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1136 KB Output is correct
2 Correct 8 ms 1212 KB Output is correct
3 Correct 6 ms 1212 KB Output is correct
4 Incorrect 7 ms 1236 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1096 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1108 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 852 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -