Submission #422137

#TimeUsernameProblemLanguageResultExecution timeMemory
422137AntekbToy Train (IOI17_train)C++14
28 / 100
581 ms117384 KiB
#include "train.h"
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb(x) push_back(x)
using namespace std;
const int N=5005;
vector<int> E[N], rE[N], E2[N], rE2[N];
int d[N];
int wsk=0;
int czy[N][N], dobre[N], petla[N];
int vis[N];
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> uu, std::vector<int> vv) {
	int n=a.size(), m=uu.size();
	std::vector<int> res(n);
	for(int i=0; i<m; i++){
		//cout<<uu[i]<<" "<<vv[i]<<"\n";
		if(uu[i]==vv[i])petla[uu[i]]=1;
		else{
			E[uu[i]].pb(vv[i]);
			rE[vv[i]].pb(uu[i]);
		}
	}
	for(int i=0; i<n; i++){
		if(r[i]){
			for(int j=0; j<n; j++)d[j]=E[j].size()+petla[j]*(1-a[j])*(1-r[j]), vis[j]=0;
			vector<int> V;
			V.push_back(i);
			for(int j=0; j<V.size(); j++){
				//cout<<i<<" "<<V[j]<<"\n";
				if(j)czy[V[j]][i]=1;
				if(V[j]==i && j!=0)continue;
				int v=V[j];
				for(int u:rE[v]){
					if(a[u] && !vis[u]){
						vis[u]=1;
						V.pb(u);
					}
					if(!a[u] && --d[u]==0){
						V.pb(u);
					}
					//assert(d[u]>=0);
				}
				if(j==0 && petla[i] && (a[i]||E[i].empty()))V.pb(i);
			}
		}
	}
	/*int c=0;
	for(int i=0; i<n; i++)if(r[i])c=i;
	//cout<<c<<"\n";
	for(int i=0; i<n;i++){
		res[i]=czy[i][c]*czy[c][c];
	}*/
	
	vector<int> V;
	for(int i=0; i<n; i++){
		if(r[i]){
			for(int j=0;j<n; j++){
				if(czy[i][j])E2[j].pb(i);
			}
		}
	}
	for(int i=0; i<n; i++)if(r[i]){
		vis[i]=0;
		if(czy[i][i])V.pb(i), vis[i]=1;
	}
	for(int i=0; i<V.size(); i++){
		int v=V[i];
		//cout<<v<<"\n";
		for(int u:E2[v]){
			if(!vis[u]){
				vis[u]=1;
				V.pb(u);
			}
		}
	}
	/*for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			cout<<czy[j][i];
		}
		cout<<"\n";
	}*/
	for(int i=0; i<n ;i++){
		for(int j=0; j<n; j++){
			if(czy[i][j] && vis[j])res[i]=1;
		}
	}
	return res;
}

Compilation message (stderr)

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |    for(int j=0; j<V.size(); j++){
      |                 ~^~~~~~~~~
train.cpp:67:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for(int i=0; i<V.size(); i++){
      |               ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...