답안 #789657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789657 2023-07-21T16:09:45 Z esomer 장난감 기차 (IOI17_train) C++17
34 / 100
226 ms 1236 KB
#include<bits/stdc++.h>
#include "train.h"
 
using namespace std;
 
typedef long long ll;
 
void process(vector<int>& A, vector<int>& R, vector<int>& U, vector<int>& V, vector<bool>& forced, vector<int>& out, vector<vector<int>>& radj){
	int n = (int)A.size();
	int m = (int)U.size();
	queue<int> q;
	for(int i = 0; i < n; i++){
		if(out[i] == 0 || R[i] == 1){
			forced[i] = 0;
			q.push(i);
		}
	}
	vector<int> org = out;
	while(!q.empty()){
		int x = q.front(); q.pop();
		for(int node : radj[x]){
			out[node]--;
			if(forced[node] == 0) continue;
			if(out[node] == 0) {q.push(node); forced[node] = 0;}
			if(A[node] == 1){
				forced[node] = 0;
				q.push(node);
			}
		}
	}
	out = org;
	for(int i = 0; i < n; i++){
		if(out[i] == 0 || forced[i] == 1){
			q.push(i);
		}
	}
	while(!q.empty()){
		int x = q.front(); q.pop();
		for(int node : radj[x]){
			out[node]--;
			if(forced[node] == 1) continue;
			if(out[node] == 0) {q.push(node); forced[node] = 1;}
			if(A[node] == 0){
				forced[node] = 1;
				q.push(node);
			}
		}
	}
	out = org;
}
 
vector<int> who_wins(vector<int> A, vector<int> R, vector<int> U, vector<int> V){
	int n = (int)A.size();
	int m = (int)U.size();
	vector<bool> forced; //If 1, then it can be forced by B into a cycle with no R's.
	vector<int> out(n);
	vector<vector<int>> radj(n);
	for(int i = 0; i < m; i++){
		radj[V[i]].push_back(U[i]);
		out[U[i]]++;
	}
	bool stop = 0;
	while(!stop){
		stop = 1;
		forced.assign(n, 1);
		process(A, R, U, V, forced, out, radj);
		for(int i = 0; i < n; i++){
			if(forced[i] == 1 && R[i] == 1) {R[i] = 0; stop = 0;}
		}
	}
	vector<int> ans(n);
	for(int i = 0; i < n; i++){
		if(forced[i] == 1) ans[i] = 0;
		else ans[i] = 1;
	}
	return ans;
}

Compilation message

train.cpp: In function 'void process(std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<bool>&, std::vector<int>&, std::vector<std::vector<int> >&)':
train.cpp:10:6: warning: unused variable 'm' [-Wunused-variable]
   10 |  int m = (int)U.size();
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 724 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Incorrect 1 ms 212 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 1080 KB Output is correct
2 Correct 115 ms 1084 KB Output is correct
3 Correct 174 ms 1060 KB Output is correct
4 Correct 5 ms 1004 KB Output is correct
5 Correct 8 ms 1212 KB Output is correct
6 Correct 6 ms 1236 KB Output is correct
7 Correct 5 ms 1236 KB Output is correct
8 Correct 5 ms 1204 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 5 ms 1108 KB Output is correct
11 Correct 5 ms 1208 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 5 ms 1236 KB Output is correct
14 Correct 5 ms 1208 KB Output is correct
15 Correct 7 ms 1236 KB Output is correct
16 Correct 5 ms 1204 KB Output is correct
17 Correct 6 ms 1176 KB Output is correct
18 Correct 226 ms 952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 852 KB Output is correct
2 Correct 5 ms 1108 KB Output is correct
3 Correct 5 ms 1236 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 5 ms 1236 KB Output is correct
6 Correct 5 ms 1236 KB Output is correct
7 Correct 6 ms 1236 KB Output is correct
8 Correct 6 ms 1236 KB Output is correct
9 Correct 5 ms 1108 KB Output is correct
10 Correct 5 ms 1236 KB Output is correct
11 Correct 5 ms 1236 KB Output is correct
12 Correct 5 ms 1208 KB Output is correct
13 Correct 5 ms 1236 KB Output is correct
14 Correct 5 ms 1172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 980 KB Output is correct
2 Correct 6 ms 1212 KB Output is correct
3 Correct 6 ms 1216 KB Output is correct
4 Correct 6 ms 1108 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 4 ms 888 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
11 Correct 3 ms 820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 724 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -