답안 #839052

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839052 2023-08-28T14:42:03 Z mohammad_kilani 장난감 기차 (IOI17_train) C++17
0 / 100
6 ms 1616 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 5010;

int n;

vector< int > ans , g[N] , g2[N] , r , a;

void make(){
	ans = vector< int > (n , -1);
	vector< int > out(n , 0);
	queue < int > q;
	for(int i = 0 ;i < n;i++){
		if(r[i]) continue;
		for(int j = 0 ;j < (int)g[i].size();j++){
			if(a[i]){
				if(r[g[i][j]]){
					out[i] = 0;
					ans[i] = 1;
					q.push(i);
					break;
				}
				out[i]++;
			}
			else{
				if(r[g[i][j]]) continue;
				out[i]++;
			}
		}
		if(out[i] == 0){
			q.push(i);
			if(ans[i] == -1){
				ans[i] = a[i] ^ 1;
			}
		}
	}
	int node;
	while(!q.empty()){
		node = q.front();
		q.pop();
		for(int pre , i = 0 ;i < (int)g2[node].size();i++){
			pre = g2[node][i];
			if(out[pre] == 0) continue;
			out[pre]--;
			if(ans[node] == a[pre]){
				out[pre] = 0;
				ans[pre] = a[pre];
				q.push(pre);
				continue;
			}
			if(out[pre] == 0){
				ans[pre] = a[pre] ^ 1;
				q.push(pre);
			}
		}
	}
	for(int i = 0 ;i < n;i++){
		if(r[i]){
			ans[i] = 1;
			continue;
		}
		if(out[i] > 0){
			ans[i] = 0;
		}
	}
}

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	n = (int)a.size();
	ans.resize(n , -1);
	::r = r;
	::a = a;
	for(int i = 0 ;i < (int)u.size();i++){
		g[u[i]].push_back(v[i]);
		g2[v[i]].push_back(u[i]);
	}
	bool found = true , good;
	while(found){
		make();
		found = false;
		for(int i = 0 ;i < n;i++){
			if(!r[i]) continue;
			good = false;
			for(int j = 0 ;j < (int)g[i].size();j++){
				if(ans[g[i][j]] == a[i]){
					good = true;
					break;
				}
			}
			if(good){
				if(!a[i]) found = true, r[i] = false;
			}
			else{
				if(a[i]) found = true, r[i] = false;
			}
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1108 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1616 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1364 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1580 KB 3rd lines differ - on the 545th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1108 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -