답안 #409819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
409819 2021-05-21T15:27:16 Z dreezy 장난감 기차 (IOI17_train) C++17
0 / 100
2000 ms 1228 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
vector<vector<int>> graph;
vector<bool> vis;
vector<int> a, r,w;

bool dfs(int n, int energy, bool charger){
	//cout << n << ", "<<energy <<", "<<charger<<endl;
	if(energy < 0 ) {
		w[n] = true;
		vis[n] = false;
		return false;
	}
	if(vis[n]){
		vis[n] = false;
		if(charger){
			w[n] = true;
			return true;
		}
		w[n] = false;
		return false;
	}
	
	vis[n] = true;
	
	
	for(int adj : graph[n]){
		if(r[adj]){
			energy = n;
			charger = true;
		}
		bool res = dfs(adj, energy--,charger);
		
		if( a[adj] == 1 && res){
			w[adj] = true;
			vis[adj] = false;
			return true;
		}
		
		if(a[adj] == 0 && !res){
			w[adj] = false;
			vis[adj] = false;
			return false;
		}
	}
	
	return false;
	
}

vector<int> who_wins(vector<int> a_, vector<int> r_, vector<int> u , vector<int> v){
	int n = a_.size();
	int m = u.size();
	graph.assign(n, {});
	vis.assign(n, 0);
	w.assign(n, 0);
	a = a_;
	r=r_;
	for(int i =0; i< m;i++){
		graph[u[i]].pb(v[i]);
	}
	
	for(int i=0; i<n;i++)
		dfs(i, n , r_[i]);
	

	return w;
}

/*
int main(){
	int n, m; cin >> n >>m;
	vector<int> a_(n), r_(n), u(m) ,v(m);
	for(int i  = 0; i<n; i++){
		cin >> a_[i];
	}
	for(int i =0; i< n; i++)
		cin >> r_[i];
	for(int i =0; i<m; i++)
	cin >> u[i];
	for(int i =0; i<m;i++)
	cin >> v[i];
	
	vector<int> w_ = who_wins(a_,r_,u,v);
	for(int i=0; i< n ;i++)
		cout << w_[i]<<endl;
}*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 716 KB 3rd lines differ - on the 3rd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2078 ms 1228 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 972 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 1084 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 716 KB 3rd lines differ - on the 3rd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -