Submission #711851

# Submission time Handle Problem Language Result Execution time Memory
711851 2023-03-17T15:17:27 Z penguinman Toy Train (IOI17_train) C++17
0 / 100
160 ms 262144 KB
#include "train.h"
#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::vector;
using ll = int;
using vi = vector<ll>;
using vii = vector<vi>;
using std::string;
using pii = std::pair<ll,ll>;

#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define ln "\n"
#define all(a) a.begin(), a.end()
#define mp std::make_pair
#define pb emplace_back

std::vector<int> wa_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	ll N = a.size();
	vii edge(N);
	rep(i,0,u.size()) edge[u[i]].pb(v[i]);
	vi dp = r;
	REP(t,0,N+100){
		rep(i,0,N){
			if(a[i] == 1){
				for(auto next: edge[i]){
					dp[i] |= dp[next];
				}
			}
			else{
				int val = 1;
				for(auto next: edge[i]){
					val &= dp[next];
				}
				dp[i] |= val;
			}
		}
	}
	rep(i,0,N) dp[i] = 1-dp[i];
	REP(t,0,N+100){
		rep(i,0,N){
			if(a[i] == 0){
				for(auto next: edge[i]){
					dp[i] |= dp[next];
				}
			}
			else{
				int val = 1;
				for(auto next: edge[i]){
					val &= dp[next];
				}
				dp[i] |= val;
			}
		}
	}
	rep(i,0,N) dp[i] = 1-dp[i];
	return dp;
}


std::vector<int> who_wins_1(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	ll N = a.size();
	vi dp(N);
	vii edge(N);
	rep(i,0,u.size()) edge[u[i]].pb(v[i]);
	per(i,N-1,0){
		if(edge[i].size() == 1 && edge[i][0] == i){
			dp[i] = r[i];
		}
		else if(edge[i].size() == 2){
			if(a[i] == 1){
				dp[i] = dp[i+1]|r[i];
			}
			else{
				dp[i] = dp[i+1]&r[i];
			}
		}
		else{
			dp[i] = dp[i+1];
		}
	}
	return dp;
}

constexpr int sz = pow(3,15);
bool dp[sz][15] = {}, flag[sz][15] = {};

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	ll N = a.size();
	assert(N <= 15);
	vii edge(N);
	rep(i,0,u.size()) edge[u[i]].pb(v[i]);
	auto idx = [&](int visited, int imp){
		int ret = 0;
		rep(i,0,N){
			ret = (visited&1)+(imp&1)+ret*3;
			visited >>= 1;
			imp >>= 1;
		}
		return ret;
	};
	rep(i,0,sz){
		rep(j,0,N) dp[i][j] = flag[i][j] = 0;
	}
	std::function<int(int,int,int)> dfs = [&](int visited, int imp, int now){
		int bit = idx(visited, imp);
		if(flag[bit][now]) return dp[bit][now];
		bool ret;
		if(a[now] == 0){
			ret = 1;
			for(auto next: edge[now]){
				if(visited & (1<<next)){
					if(imp & (1<<next)) ret = 0;
				}
				else{
					if(r[next] == 0) ret &= dfs(visited|(1<<next), imp|(1<<next), next);
					else ret &=dfs(visited|(1<<next), 0, next);
				}
			}
		}
		else{
			ret = 0;
			for(auto next: edge[now]){
				if(visited & (1<<next)){
					if(imp & (1<<next)) continue;
					else ret = 1;
				}
				else{
					if(r[next] == 0) ret |= dfs(visited|(1<<next), imp|(1<<next), next);
					else ret |=dfs(visited|(1<<next), 0, next);
				}
			}
		}
		flag[bit][now] = true;
		return dp[bit][now] = ret;
	};
	vi ans(N);
	rep(i,0,N){
		int imp = 0;
		if(r[i] == 0) imp = (1<<i);
		ans[i] = dfs((1<<i), imp, i);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 852 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 160 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 1388 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 1236 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 1392 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 852 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -