Submission #33546

# Submission time Handle Problem Language Result Execution time Memory
33546 2017-10-29T17:14:44 Z mohammad_kilani Toy Train (IOI17_train) C++14
0 / 100
2000 ms 3056 KB
#include <bits/stdc++.h>
#include "train.h"
using namespace std;
const int N = 5010;
int n ;
bitset< N > dp , win ;
int vis[N] , vi = 0;
vector<int> g[N] , a , r;
bool solve(int i, int j){
	if(r[i]) return 1;
	if(i == j) return 0;
	if(vis[i] == vi) return dp[i];
	vis[i] = vi;
	dp[i] = 1;
	if(!a[i]){
		for(int k=0;k<g[i].size();k++){
			int node = g[i][k];
			if(solve(node,j) == 0) dp[i] = 0;
		}
	}
	else{
		bool can = false;
		for(int k=0;k<g[i].size();k++){
			int node = g[i][k];
			if(node != j && solve(node,j) == 1) can = true;
		}
		dp[i] = can;
	}
	return dp[i];
}

bool solve2(int i){
	if(win[i] == 0) return 0;
	if(vis[i] == vi) return dp[i];
	vis[i] = vi;
	dp[i] = 1;
	if(!a[i]){
		for(int k=0;k<g[i].size();k++){
			int node = g[i][k];
			if(solve2(node) == 0) dp[i] = 0;
		}
	}
	else{
		bool can = false;
		for(int k=0;k<g[i].size();k++){
			int node = g[i][k];
			if(solve2(node) == 1) can = true;
		}
		dp[i] = can;
	}
	return dp[i];
}


std::vector<int> who_wins(std::vector<int> A, std::vector<int> R, std::vector<int> u, std::vector<int> v) {
	vector<int> ans;
	a = A;
	r = R;;
	n = a.size();
	for(int i=0;i<u.size();i++) g[u[i]].push_back(v[i]);
	for(int i=0;i<n;i++){
		vi++;
		bool can = 1;
		if(!a[i]){
			for(int j=0;j<g[i].size();j++){
				if(solve(g[i][j],i) == 0) can = 0;
			}
		}
		else{
			can = 0;
			for(int j=0;j<g[i].size();j++){
				if(solve(g[i][j],i) == 0) can = 1;
			}
		}
		win[i] = can;
	}
	vi++;
	for(int i=0;i<n;i++){
		bool can = 1;
		if(solve2(i) == 0) can = 0;
		win[i] = can;
		ans.push_back(win[i]);
	}
	return ans;
}

Compilation message

train.cpp: In function 'bool solve(int, int)':
train.cpp:16:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int k=0;k<g[i].size();k++){
                ^
train.cpp:23:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int k=0;k<g[i].size();k++){
                ^
train.cpp: In function 'bool solve2(int)':
train.cpp:38:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int k=0;k<g[i].size();k++){
                ^
train.cpp:45:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int k=0;k<g[i].size();k++){
                ^
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:60:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<u.size();i++) g[u[i]].push_back(v[i]);
               ^
train.cpp:65:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<g[i].size();j++){
                 ^
train.cpp:71:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<g[i].size();j++){
                 ^
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2568 KB 3rd lines differ - on the 5th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2156 KB 3rd lines differ - on the 6th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 206 ms 3056 KB 3rd lines differ - on the 1663rd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Incorrect 193 ms 2748 KB 3rd lines differ - on the 666th token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2000 ms 2972 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2568 KB 3rd lines differ - on the 5th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -