제출 #596142

#제출 시각아이디문제언어결과실행 시간메모리
596142kshitij_sodani장난감 기차 (IOI17_train)C++14
38 / 100
2086 ms1484 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define a first
#define b second
#define pb push_back
#define endl '\n'


#include "train.h"
vector<int> adj[5001];
vector<int> adj2[5001];

int co[5001];
int vis[5001];
std::vector<int> who_wins(std::vector<int> aa, std::vector<int> bb, std::vector<int> u, std::vector<int> v) {
	int n=aa.size();
	for(int i=0;i<u.size();i++){
		adj[u[i]].pb(v[i]);
		adj2[v[i]].pb(u[i]);
	}
	int ind=-1;
	vector<int> ss;
	for(int i=0;i<n;i++){
		if(bb[i]==1){
			ind=i;
			ss.pb(ind);
		}
	}
	vector<int> cc=bb;

	while(true){
		vector<int> ss;
		queue<int> tt;
		for(int i=0;i<n;i++){
			co[i]=adj[i].size();
			if(cc[i]==1){
				ind=i;
				tt.push(i);
				ss.pb(ind);
				vis[i]=1;
			}
			else{
				vis[i]=0;
			}
		}
		bb=cc;
		while(tt.size()){
			int no=tt.front();
			tt.pop();
			int st=1;
			for(auto j:adj2[no]){
				if(vis[j]==0){
					if(aa[j]==1){
						vis[j]=1;
						bb[j]=1;
						tt.push(j);
					}
					else{
						co[j]--;
						if(co[j]==0){
							vis[j]=1;
							bb[j]=1;
							tt.push(j);
						}
					}
				}
			}

			for(int i=0;i<n;i++){
				if(bb[i]==0){
					int su=0;
					for(auto j:adj[i]){
						su+=bb[j];
					}
					if(aa[i]==1){
						if(su>0){
							bb[i]=1;
							st=0;
						}
					}
					else{
						if(su==adj[i].size()){
							bb[i]=1;
							st=0;
						}
					}
				}
			}
			if(st==1){
				break;
			}
		}
		int st=1;
		for(auto j:ss){
			int su=0;
			for(auto jj:adj[j]){
				su+=bb[jj];
			}
			if(aa[j]==1){
				if(su==0){
					st=0;
					cc[j]=0;
					break;
				}
			}
			else{
				if(su<adj[j].size()){
					st=0;
					cc[j]=0;
					cc[j]=0;
				}
			}
		}
		if(st==1){
			break;
		}
	}
	
	
	return bb;
	/*for(auto j:adj[ind]){
		if(bb[j]==1){
			for(int i=0;i<n;i++){
				if(bb[i]==1){
					ans[i]=1;
				}
			}
			break;
		}
	}
	return ans;*/
}

컴파일 시 표준 에러 (stderr) 메시지

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:18:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for(int i=0;i<u.size();i++){
      |              ~^~~~~~~~~
train.cpp:83:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |       if(su==adj[i].size()){
      |          ~~^~~~~~~~~~~~~~~
train.cpp:108:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     if(su<adj[j].size()){
      |        ~~^~~~~~~~~~~~~~
#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...