답안 #1048109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048109 2024-08-07T22:50:59 Z Trent 장난감 기차 (IOI17_train) C++17
5 / 100
5 ms 1504 KB
#include "train.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;

void dfs(int c, vb& vis, vb& aWin, vvi& adj, vi& a, vi& r) {
	assert(!vis[c]);
	vis[c] = true;
	if(adj[c].size() == 2) {
		// next and cur
		if(a[c] == 1 && r[c] == 1) {
			aWin[c] = true;
			return;
		} else if(a[c] == 0 && r[c] == 0) {
			aWin[c] = false;
			return;
		} else {
			int nex = adj[c][0] == c ? adj[c][1] : adj[c][0];
			if(!vis[nex]) dfs(nex, vis, aWin, adj, a, r);
			aWin[c] = aWin[nex];
			return;
		}
	} else {
		if(adj[c][0] != c) {
			int nex = adj[c][0];
			if(!vis[nex]) dfs(nex, vis, aWin, adj, a, r);
			aWin[c] = aWin[nex];
			return;
		} else {
			aWin[c] = r[c] == 1;
		}
	}
}
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();
	vvi adj(n);
	forR(i, m) {
		adj[u[i]].push_back(v[i]);
	}
	vi ret(n);
	vb vis(n, false), aWin(n, false);
	forR(i, n) {
		if(!vis[i]) {
			dfs(i, vis, aWin, adj, a, r);
		}
		ret[i] = aWin[i] ? 1 : 0;
	}
	return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 864 KB Output is correct
5 Correct 2 ms 828 KB Output is correct
6 Correct 2 ms 856 KB Output is correct
7 Correct 2 ms 868 KB Output is correct
8 Correct 3 ms 872 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1116 KB Output is correct
2 Correct 3 ms 1504 KB Output is correct
3 Correct 4 ms 1476 KB Output is correct
4 Incorrect 4 ms 1348 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 860 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1116 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 864 KB Output is correct
5 Correct 2 ms 828 KB Output is correct
6 Correct 2 ms 856 KB Output is correct
7 Correct 2 ms 868 KB Output is correct
8 Correct 3 ms 872 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Incorrect 0 ms 348 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
13 Halted 0 ms 0 KB -