답안 #775883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
775883 2023-07-07T05:58:50 Z Jomnoi 장난감 기차 (IOI17_train) C++17
0 / 100
400 ms 1320 KB
#include <bits/stdc++.h>
#include "train.h"
using namespace std;

const int MAX_N = 5005;
const int MAX_M = 20005;

int N, M;
vector <int> graph[MAX_N];
int A[MAX_N], R[MAX_N];
bool visited[MAX_N];
bool self[MAX_N], nxt[MAX_N];

bool dfs(int u, int x, bool found, bool init = false) {
	// cout << x << " : " << u << ' ' << found << endl;
	if (u == x and init == true) return found;
	if (visited[u] == true) return false;

	init = true;
	visited[u] = true;
	if (R[u] == 1) found = true;
	for (auto v : graph[u]) if (dfs(v, x, found, true) == true) return true;
	return false;
}

vector <int> who_wins(vector <int> a, vector <int> r, vector <int> u, vector <int> v) {
	N = a.size(), M = u.size();
	for (int i = 0; i < N; i++) A[i] = a[i], R[i] = r[i];
	bool sub1 = true;
	for (int i = 0; i < M; i++) {
		if (u[i] != v[i] and u[i] != v[i] - 1) sub1 = false;
		if (u[i] == v[i]) self[u[i]] = true;
		else if (u[i] + 1 == v[i]) nxt[u[i]] = true;
		graph[u[i]].push_back(v[i]);
	}

	vector <int> ans;
	if (sub1 == true) {
		bool ok1 = false, ok2 = false;
		for (int s = N - 1; s >= 0; s--) {
			if (A[s] == 1 and self[s] == true) ok1 = true;
			if (A[s] == 0 and nxt[s] == false and self[s] == true) ok1 = true;
			if (R[s] == 1) ok2 = true;

			if (ok1 == true and ok2 == true) ans.push_back(1); 
			else ans.push_back(0);
		}
		reverse(ans.begin(), ans.end());
	}
	else {
		for (int s = 0; s < N; s++) {
			for (int i = 0; i < N; i++) visited[i] = false;
			ans.push_back(dfs(s, s, false));
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 852 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB 3rd lines differ - on the 8th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 1316 KB Output is correct
2 Correct 121 ms 1284 KB Output is correct
3 Correct 120 ms 1244 KB Output is correct
4 Incorrect 342 ms 1320 KB 3rd lines differ - on the 13th token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 298 ms 1096 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 400 ms 1304 KB 3rd lines differ - on the 6th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 852 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -