답안 #423140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423140 2021-06-10T18:45:53 Z Rudy420 장난감 기차 (IOI17_train) C++17
28 / 100
284 ms 1740 KB
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define lg length()
#define pb push_back
#define INF 2000000005
#define LINF 1000000000000000005
#define all(x) (x).begin(), (x).end()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
#include "train.h"

int n,m;

vector <vector<int>> g, h;

int count_ones(vector<int> &a){
	int ans = 0;
	for(int i=0;i<n;i++){
		ans += a[i];
	}
	return ans;
}

void f(vector<int> &s, vector<int> &w, vector<int> &a, int id){
	queue<int> q;
	vector<int> d(n);
	for(int i=0;i<n;i++){
		if(s[i]) q.push(i);
		d[i] = sz(g[i]);
	}
	while(sz(q)){
		int i = q.front();
		q.pop();
		for(int j : h[i]){
			if(s[j]) continue;
			d[j]--;
			if(a[j] == id || d[j] == 0){
				s[j] = 1;
				q.push(j);
			}
		}
	}
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
	n = sz(a);
	m = sz(u);
	vector<int> w(n, 1);
	vector<int> ans(n, 1);
	for(int i=0;i<n;i++) g.pb({}), h.pb({});
	for(int i=0;i<m;i++) g[u[i]].pb(v[i]), h[v[i]].pb(u[i]);

	vector<int> s(n);
	while(1){
		for(int i=0;i<n;i++){
			if(r[i] && w[i]) s[i] = 1;
			else s[i] = 0;
		}
		f(s, w, a, 1);
		if(count_ones(s) == count_ones(w)) break;
		for(int i=0;i<n;i++){
			if(!s[i] && w[i]) s[i] = 1;
			else s[i] = 0;
		}
		f(s, w, a, 0);
		for(int i=0;i<n;i++){
			if(s[i]) ans[i] = 0, w[i] = 0;
		}
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1100 KB Output is correct
2 Correct 7 ms 1220 KB Output is correct
3 Correct 6 ms 1100 KB Output is correct
4 Correct 6 ms 1228 KB Output is correct
5 Correct 6 ms 1104 KB Output is correct
6 Correct 6 ms 1104 KB Output is correct
7 Correct 5 ms 1140 KB Output is correct
8 Correct 6 ms 1100 KB Output is correct
9 Correct 6 ms 1076 KB Output is correct
10 Correct 5 ms 1100 KB Output is correct
11 Correct 5 ms 1080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Incorrect 1 ms 204 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 1684 KB Output is correct
2 Correct 212 ms 1672 KB Output is correct
3 Correct 284 ms 1676 KB Output is correct
4 Correct 10 ms 1740 KB Output is correct
5 Incorrect 10 ms 1612 KB 3rd lines differ - on the 11th token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1456 KB Output is correct
2 Correct 8 ms 1484 KB Output is correct
3 Correct 9 ms 1612 KB Output is correct
4 Correct 9 ms 1612 KB Output is correct
5 Correct 9 ms 1612 KB Output is correct
6 Correct 10 ms 1612 KB Output is correct
7 Correct 9 ms 1580 KB Output is correct
8 Correct 9 ms 1612 KB Output is correct
9 Correct 9 ms 1484 KB Output is correct
10 Correct 9 ms 1572 KB Output is correct
11 Correct 9 ms 1612 KB Output is correct
12 Correct 9 ms 1680 KB Output is correct
13 Correct 9 ms 1612 KB Output is correct
14 Correct 9 ms 1612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1644 KB Output is correct
2 Correct 9 ms 1612 KB Output is correct
3 Correct 10 ms 1652 KB Output is correct
4 Correct 8 ms 1484 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 5 ms 1192 KB Output is correct
7 Correct 5 ms 972 KB Output is correct
8 Correct 6 ms 972 KB Output is correct
9 Correct 8 ms 972 KB Output is correct
10 Correct 2 ms 436 KB Output is correct
11 Correct 5 ms 948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1100 KB Output is correct
2 Correct 7 ms 1220 KB Output is correct
3 Correct 6 ms 1100 KB Output is correct
4 Correct 6 ms 1228 KB Output is correct
5 Correct 6 ms 1104 KB Output is correct
6 Correct 6 ms 1104 KB Output is correct
7 Correct 5 ms 1140 KB Output is correct
8 Correct 6 ms 1100 KB Output is correct
9 Correct 6 ms 1076 KB Output is correct
10 Correct 5 ms 1100 KB Output is correct
11 Correct 5 ms 1080 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Incorrect 1 ms 204 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
20 Halted 0 ms 0 KB -