Submission #293211

# Submission time Handle Problem Language Result Execution time Memory
293211 2020-09-07T18:46:21 Z eohomegrownapps Toy Train (IOI17_train) C++14
16 / 100
1556 ms 2296 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

int n,m;

vector<vector<int>> adjlist;
vector<vector<int>> revadjlist;

vector<bool> status;
vector<int> cp;

bool dfs(int node, int ret){
	//cout<<"dfs "<<node<<' '<<ret<<endl;
	if (node-n==ret){
		return true;
	}
	status[node]=true;
	bool hascharged = node>=n;
	if (cp[node-(hascharged*n)]&&(!hascharged)){
		node+=n;
		hascharged=true;
	}

	int nd = node-(hascharged*n);
	for (int i : adjlist[nd]){
		if (status[i+(hascharged*n)]){
			continue;
		}
		if (dfs(i+(hascharged*n),ret)){
			return true;
		}
	}
	return false;
}

vector<int> aall(vector<int> &charging, vector<int> &u, vector<int> &v){
	adjlist.resize(n);
	revadjlist.resize(n);
	for (int i = 0; i<m; i++){
		adjlist[u[i]].push_back(v[i]);
		revadjlist[v[i]].push_back(u[i]);
	}
	//cout<<"bleh"<<endl;
	cp=charging;
	vector<int> use;
	for (int i = 0; i<n; i++){
		// is there cycle from this node involving a charging point?
		status.assign(2*n,false);
		if (dfs(i,i)){
			use.push_back(i);
		}
	}
	//cout<<"bleh"<<endl;
	vector<int> visited(n,0);
	queue<int> q;
	for (int i : use){
		visited[i]=1;
		q.push(i);
	}
	while (q.size()>0){
		int f = q.front();
		q.pop();
		for (int i : revadjlist[f]){
			if (!visited[i]){
				visited[i]=1;
				q.push(i);
			}
		}
	}
	return visited;
}

vector<int> ball(vector<int> &charging, vector<int> &u, vector<int> &v){
	return vector<int>();
}

std::vector<int> who_wins(std::vector<int> aowns, std::vector<int> charging, std::vector<int> u, std::vector<int> v) {
	n=aowns.size();
	m=u.size();
	int numa = 0;
	for (int i : aowns){
		numa+=i;
	}
	if (numa==n){
		return aall(charging,u,v);
	}
	/*if (numa==0){
		return ball(charging,u,v);
	}*/

	vector<bool> iscycle(n);
	vector<bool> edgetonext(n,false);
	for (int i = 0; i<m; i++){
		if (u[i]==v[i]){
			iscycle[u[i]]=true;
		} else {
			edgetonext[u[i]]=true;
		}
	}
	vector<int> ans(n);
	for (int i = n-1; i>=0; i--){
		if (iscycle[i]){
			if (aowns[i]&&charging[i]){
				ans[i]=1;
			} else if ((!aowns[i])&&(!charging[i])){
				ans[i]=0;
			} else {
				if (!edgetonext[i]){
					if (charging[i]){
						ans[i]=1;
					} else {
						ans[i]=0;
					}
				} else {
					ans[i]=ans[i+1];
				}
			}
		} else {
			ans[i]=ans[i+1];
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 4 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 4 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 7 ms 1152 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 209 ms 1784 KB Output is correct
2 Correct 221 ms 1752 KB Output is correct
3 Correct 219 ms 1664 KB Output is correct
4 Correct 570 ms 1776 KB Output is correct
5 Correct 650 ms 1788 KB Output is correct
6 Correct 896 ms 1780 KB Output is correct
7 Correct 479 ms 1656 KB Output is correct
8 Correct 440 ms 1660 KB Output is correct
9 Correct 306 ms 1656 KB Output is correct
10 Correct 701 ms 1656 KB Output is correct
11 Correct 487 ms 1536 KB Output is correct
12 Correct 31 ms 1528 KB Output is correct
13 Correct 1098 ms 2040 KB Output is correct
14 Correct 1556 ms 2168 KB Output is correct
15 Correct 1272 ms 2296 KB Output is correct
16 Correct 478 ms 1948 KB Output is correct
17 Correct 555 ms 1912 KB Output is correct
18 Correct 370 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 768 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 768 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 4 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 4 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 7 ms 1152 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Incorrect 0 ms 384 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
13 Halted 0 ms 0 KB -