답안 #408455

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
408455 2021-05-19T07:32:11 Z 8e7 장난감 기차 (IOI17_train) C++14
0 / 100
16 ms 1540 KB
#include "train.h"
 
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#define ll long long
#define maxn 5005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int own[maxn], del[maxn];
vector<int> adj[maxn], rev[maxn];
vector<int> f(int a, vector<int> st, int n) {
	bool found[n];
	int deg[n];
	for (int i = 0;i < n;i++){ 
		found[i] = 0;
		deg[i] = 0;
		for (int j:adj[i]) {
			if (!del[j]) deg[i]++;
		}
	}
	
	queue<int> que;
	for (int i:st) {
		found[i] = 1;
		que.push(i);
	}	
	while (que.size()) {
		int cur = que.front();que.pop();
		found[cur] = 1;
		for (int v:rev[cur]) {
			if (found[v] || del[v]) continue;
			deg[v]--;
			if (own[v] == a || deg[v] == 0) {
				found[v] = 1;
				que.push(v);
			}
		}
	}
	vector<int> ret (n, 0);
	for (int i = 0;i < n;i++) ret[i] = found[i] ? 1 : 0;
	return ret;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	int n = a.size(), m = u.size();
	vector<int> b;
	for (int i = 0;i < n;i++){
		own[i] = a[i];
		if (r[i]) b.push_back(i);
	}
	for (int i = 0;i < m;i++) {
		adj[u[i]].push_back(v[i]);
		rev[v[i]].push_back(u[i]);
	}
	vector<int> ret(n, 0);
	while (true) {
		vector<int> fa = f(1, b, n);
		vector<int> t;
		for (int i = 0;i < n;i++) {
			if (!fa[i] && !del[i]) t.push_back(i);
		}
		//cout << endl;
		//for (int i:t) cout << i << " ";
		//cout << endl;
		vector<int> fb = f(0, t, n);
		int found = 0;
		for (int i = 0;i < n;i++) {
			if (fb[i]) {
				found = 1;
				del[i] = 1;
			}
		}
		if (!found) {
			for (int i = 0;i < n;i++) {
				if (fa[i]) ret[i] = 1;
			}
			break;
		}
	}
	return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1136 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 464 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 1484 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 1376 KB 3rd lines differ - on the 3065th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 1500 KB Output is correct
2 Correct 13 ms 1356 KB Output is correct
3 Correct 15 ms 1540 KB Output is correct
4 Correct 12 ms 1356 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Incorrect 5 ms 1100 KB 3rd lines differ - on the 3730th token, expected: '0', found: '1'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1136 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -