Submission #409836

# Submission time Handle Problem Language Result Execution time Memory
409836 2021-05-21T15:57:30 Z dreezy Toy Train (IOI17_train) C++17
0 / 100
209 ms 1628 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
vector<vector<int>> graph;
vector<bool> vis;
vector<int> r;

int chargerind;
vector<int> ord;
bool dfs(int n, int energy, bool charger, int order){
	//cout << n << ", "<<energy << ", "<<charger<<", "<<order<<endl;
	if(vis[n]){
		if(charger && chargerind >= ord[n]){
			//cout << chargerind <<" "<<n<<" "<<ord[n]<<endl;
			return true;
		}
		return false;
	}
	
	vis[n] = true;
	ord[n] = order;
	
	for(int adj : graph[n]){
		if(r[adj]){
			energy = r.size();
			chargerind = order;
			charger = true;
		}
		bool res = dfs(adj, energy--,charger, order+1);
		
		if( res){
			return true;
		}
		
	}
	
	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);
	vector<int> w(n,0);
	r=r_;
	for(int i =0; i< m;i++){
		graph[u[i]].pb(v[i]);
		//cout << u[i]<<" ->" <<v[i]<<endl;
	}
	
	for(int i=0; i<n;i++){
		//cout << i<<": "<<endl;
		chargerind = -1;
		if(r_[i]) chargerind = 0;
		vis.assign(n, 0);
		ord.assign(n,0);
		w[i] = dfs(i, n , r_[i], 0);
	}
	

	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;
}
*/
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 844 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 209 ms 1628 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 1064 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 1280 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 844 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -