Submission #371799

# Submission time Handle Problem Language Result Execution time Memory
371799 2021-02-27T05:49:05 Z stonejjun03 Toy Train (IOI17_train) C++14
0 / 100
2000 ms 49132 KB
#include "train.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back

ll ans[1010101];
ll chk[1010101];
ll ind[1010101];
ll cnt[1010101];
ll vis[1010101];
ll vis2[1010101];
ll gp[1010101];
queue<ll> q;
vector<ll> v[1010101];
vector<ll> rev[1010101];

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> s) {
	ll i,j,k,l,m,n=a.size();
	std::vector<int> res(n);
	for(i=0;i<u.size();i++){
		v[u[i]].pb(s[i]);
		rev[s[i]].pb(u[i]);
		ind[u[i]]++;
	}
	ll fl=1;
	while(fl){
		fl=0;
		for(i=0;i<n;i++){
			vis[i]=0;
			cnt[i]=0;
			chk[i]=0;
			if(r[i]==1)
				vis[i]=1, q.push(i);
			
		}
		
		while(q.size()){
			ll x=q.front(); q.pop();
			chk[x]=1;
			for(auto k:rev[x]){
				if(vis[k]) continue;
				cnt[k]++;
				if(a[k]==1&&cnt[k]==1) vis[k]=1,q.push(k);
				if(a[k]==0&&cnt[k]==ind[k]) vis[k]=1,q.push(k);
			}
		}

		for(i=0;i<n;i++){
			cnt[i]=0;
			ans[i]=vis[i];
			vis2[i]=0;
			if(chk[i]==0) 
				vis2[i]=1,q.push(i);
		}

		while(q.size()){
			ll x=q.front(); q.pop();
			chk[x]=0;
			for(auto k:rev[x]){	
				if(vis2[k]) continue;
				cnt[k]++;
				if(a[k]==0&&cnt[k]==1) vis2[k]=1,q.push(k);
				if(a[k]==1&&cnt[k]==ind[k]) vis2[k]=1,q.push(k);
			}
		}
		for(i=0;i<n;i++){
			if(r[i]&&chk[i]==0){
				r[i]==0;
				fl=1;
			}
		}

	}


	for(i=0;i<n;i++)
		res[i]=chk[i];
	return res;
}

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:21:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for(i=0;i<u.size();i++){
      |          ~^~~~~~~~~
train.cpp:69:9: warning: value computed is not used [-Wunused-value]
   69 |     r[i]==0;
train.cpp:19:7: warning: unused variable 'j' [-Wunused-variable]
   19 |  ll i,j,k,l,m,n=a.size();
      |       ^
train.cpp:19:9: warning: unused variable 'k' [-Wunused-variable]
   19 |  ll i,j,k,l,m,n=a.size();
      |         ^
train.cpp:19:11: warning: unused variable 'l' [-Wunused-variable]
   19 |  ll i,j,k,l,m,n=a.size();
      |           ^
train.cpp:19:13: warning: unused variable 'm' [-Wunused-variable]
   19 |  ll i,j,k,l,m,n=a.size();
      |             ^
# Verdict Execution time Memory Grader output
1 Execution timed out 2081 ms 48620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2093 ms 48000 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2100 ms 49132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 49012 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 49132 KB Output is correct
2 Correct 44 ms 49132 KB Output is correct
3 Correct 43 ms 49132 KB Output is correct
4 Correct 47 ms 49004 KB Output is correct
5 Correct 33 ms 47852 KB Output is correct
6 Execution timed out 2098 ms 48620 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2081 ms 48620 KB Time limit exceeded
2 Halted 0 ms 0 KB -