Submission #1105100

# Submission time Handle Problem Language Result Execution time Memory
1105100 2024-10-25T11:48:58 Z alexander707070 Toy Train (IOI17_train) C++14
10 / 100
11 ms 31408 KB
#include<bits/stdc++.h>
#define MAXN 1000007
using namespace std;
 
int n;
bool is[MAXN],sp[MAXN],ok[MAXN],li[MAXN];
vector<int> v[MAXN],ans;
int tim[MAXN],comp[MAXN],k;

void dfs(int x){
	li[x]=true;
	comp[x]=k;

	if(sp[x])ok[k]=true;

	for(int i:v[x]){
		if(!li[i])dfs(i);
	}
}
 
bool brute(int x,int last,int t){
	tim[x]=t;
	if(sp[x])last=t;
 
	for(int i=0;i<v[x].size();i++){
		if(is[x]){
			if(tim[v[x][i]]!=0 and tim[v[x][i]]<=last){
				tim[x]=0; return true;
			}
		}else{
			if(tim[v[x][i]]!=0 and tim[v[x][i]]>last){
				tim[x]=0; return false;
			}
		}
	}
 
	for(int i=0;i<v[x].size();i++){
		if(tim[v[x][i]]!=0)continue;
 
		if(is[x]){
			if(brute(v[x][i],last,t+1)){
				tim[x]=0; return true;
			}
		}else{
			if(!brute(v[x][i],last,t+1)){
				tim[x]=0; return false;
			}
		}
	}
 
	tim[x]=0;
	return !is[x];
}
 
vector<int> who_wins(vector<int> A,vector<int> R, vector<int> from,vector<int> to){
	n=int(A.size());
	
	int mins=1,maxs=0;
	for(int i=1;i<=n;i++){
		is[i]=A[i-1];

		mins=min(mins,int(is[i]));
		maxs=max(maxs,int(is[i]));

		sp[i]=R[i-1];
	}
 
	for(int i=1;i<=from.size();i++){
		v[from[i-1]+1].push_back(to[i-1]+1);
	}
 
	if(n<=15){
		for(int i=1;i<=n;i++){
			for(int f=1;f<=n;f++)tim[f]=0;
 
			if(brute(i,0,1))ans.push_back(1);
			else ans.push_back(0);
		}
	}else{
		if(mins==maxs and mins==1){
			for(int i=1;i<=n;i++){
				if(li[i])continue;
				k++; dfs(i);
			}

			for(int i=1;i<=n;i++){
				if(ok[comp[i]])ans.push_back(1);
				else ans.push_back(0);
			}
		}
	}
 
	return ans;
}
 
/*int main(){
 
	ans=who_wins({0, 1}, {1, 0}, {0, 0, 1, 1}, {0, 1, 0, 1});
 
	for(int i:ans)cout<<i<<" ";
 
	return 0;
}*/

Compilation message

train.cpp: In function 'bool brute(int, int, int)':
train.cpp:25:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for(int i=0;i<v[x].size();i++){
      |              ~^~~~~~~~~~~~
train.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i=0;i<v[x].size();i++){
      |              ~^~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:68:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for(int i=1;i<=from.size();i++){
      |              ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 29520 KB WA in grader: Wrong returned array size
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31056 KB Output is correct
2 Correct 5 ms 31056 KB Output is correct
3 Correct 5 ms 31220 KB Output is correct
4 Correct 5 ms 31056 KB Output is correct
5 Correct 5 ms 31232 KB Output is correct
6 Correct 5 ms 31056 KB Output is correct
7 Correct 6 ms 31056 KB Output is correct
8 Correct 6 ms 31056 KB Output is correct
9 Correct 6 ms 31056 KB Output is correct
10 Correct 5 ms 31056 KB Output is correct
11 Correct 5 ms 31056 KB Output is correct
12 Correct 6 ms 31408 KB Output is correct
13 Correct 6 ms 31056 KB Output is correct
14 Correct 6 ms 31056 KB Output is correct
15 Correct 6 ms 31216 KB Output is correct
16 Correct 6 ms 31056 KB Output is correct
17 Correct 6 ms 31104 KB Output is correct
18 Correct 7 ms 31228 KB Output is correct
19 Correct 6 ms 31180 KB Output is correct
20 Correct 6 ms 31184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 30032 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 9 ms 29776 KB WA in grader: Wrong returned array size
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 29900 KB WA in grader: Wrong returned array size
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 29520 KB WA in grader: Wrong returned array size
2 Halted 0 ms 0 KB -