답안 #423145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423145 2021-06-10T18:49:51 Z Rudy420 장난감 기차 (IOI17_train) C++17
28 / 100
305 ms 1568 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(!w[j] || 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> 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] && ans[i]) s[i] = 1;
			else s[i] = 0;
		}
		f(s, ans, a, 1);
		if(count_ones(s) == count_ones(ans)) break;
		for(int i=0;i<n;i++){
			if(!s[i] && ans[i]) s[i] = 1;
			else s[i] = 0;
		}
		f(s, ans, a, 0);
		for(int i=0;i<n;i++){
			if(s[i]) ans[i] = 0;
		}
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1104 KB Output is correct
2 Correct 6 ms 1112 KB Output is correct
3 Correct 6 ms 1104 KB Output is correct
4 Correct 6 ms 1116 KB Output is correct
5 Correct 6 ms 1036 KB Output is correct
6 Correct 6 ms 1100 KB Output is correct
7 Correct 5 ms 1100 KB Output is correct
8 Correct 6 ms 1100 KB Output is correct
9 Correct 5 ms 1100 KB Output is correct
10 Correct 5 ms 1016 KB Output is correct
11 Correct 5 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 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 118 ms 1472 KB Output is correct
2 Correct 239 ms 1452 KB Output is correct
3 Correct 305 ms 1568 KB Output is correct
4 Correct 9 ms 1356 KB Output is correct
5 Incorrect 10 ms 1432 KB 3rd lines differ - on the 11th token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1232 KB Output is correct
2 Correct 8 ms 1228 KB Output is correct
3 Correct 9 ms 1512 KB Output is correct
4 Correct 13 ms 1532 KB Output is correct
5 Correct 11 ms 1340 KB Output is correct
6 Correct 13 ms 1372 KB Output is correct
7 Correct 10 ms 1356 KB Output is correct
8 Correct 8 ms 1356 KB Output is correct
9 Correct 11 ms 1236 KB Output is correct
10 Correct 11 ms 1388 KB Output is correct
11 Correct 9 ms 1356 KB Output is correct
12 Correct 12 ms 1388 KB Output is correct
13 Correct 10 ms 1428 KB Output is correct
14 Correct 9 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1428 KB Output is correct
2 Correct 9 ms 1436 KB Output is correct
3 Correct 9 ms 1356 KB Output is correct
4 Correct 8 ms 1232 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 5 ms 976 KB Output is correct
7 Correct 6 ms 844 KB Output is correct
8 Correct 6 ms 836 KB Output is correct
9 Correct 8 ms 828 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 5 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1104 KB Output is correct
2 Correct 6 ms 1112 KB Output is correct
3 Correct 6 ms 1104 KB Output is correct
4 Correct 6 ms 1116 KB Output is correct
5 Correct 6 ms 1036 KB Output is correct
6 Correct 6 ms 1100 KB Output is correct
7 Correct 5 ms 1100 KB Output is correct
8 Correct 6 ms 1100 KB Output is correct
9 Correct 5 ms 1100 KB Output is correct
10 Correct 5 ms 1016 KB Output is correct
11 Correct 5 ms 972 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 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 -