답안 #584656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584656 2022-06-27T18:40:16 Z 1ne 장난감 기차 (IOI17_train) C++14
5 / 100
8 ms 1248 KB
#include "train.h"
#include<bits/stdc++.h>
using namespace std;
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	int n = (int)a.size();
	int m = (int)u.size();
	vector<int>ans(n);
	vector<vector<int>>adj(n);
	for (int i = 0;i<m;++i){
		adj[u[i]].push_back(v[i]);
	}
	vector<bool>visited(n,false);
	vector<int>cnt(n,0);
	function<int(int)>dfs = [&](int u){
		if (visited[u])return cnt[u];
		visited[u] = true;
		int ans = 0;
		for (auto x:adj[u]){
			if (a[u] == 1 && r[u] == 1 && x == u){
				ans = (int)adj[u].size();
				break;
			}
			else if (x == u + 1){
				ans+=dfs(x);
			}
			else if (a[u] == 0 && r[u] == 0 && x == u){
				ans = -1;
				break;
			}
			else if (a[u] == 0 && r[u] == 1 && x == u){
				ans++;
			}
		}
		if (a[u] == 1){
			return cnt[u] = (ans > 0);
		}
		return cnt[u] = (ans == (int)adj[u].size());
	};
	for (int i = 0;i<n;++i){
		if (visited[i]){
			ans[i] = cnt[i];
		}
		else{
			ans[i] = dfs(i);
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 3 ms 816 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Correct 4 ms 852 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 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 5 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1208 KB Output is correct
2 Correct 6 ms 1236 KB Output is correct
3 Correct 5 ms 1248 KB Output is correct
4 Incorrect 6 ms 1236 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 980 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1236 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 3 ms 816 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Correct 4 ms 852 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 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 5 ms 724 KB Output is correct
12 Incorrect 1 ms 212 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
13 Halted 0 ms 0 KB -