Submission #607421

# Submission time Handle Problem Language Result Execution time Memory
607421 2022-07-26T17:03:29 Z fvogel499 Toy Train (IOI17_train) C++17
0 / 100
108 ms 262144 KB
#include "train.h"
#include <bits/stdc++.h>
 
using namespace std;
 
#define vi vector<int>
#define size(x) (int)((x).size())
 
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	int n = size(a);
	int SC = 2;
	for (int i : r) if (i) SC++;
	SC = n+10;
	int chargingStation = -1;
	for (int i = 0; i < n; i++) if (r[i]) {
		chargingStation = i;
	}
	vector<vi> graph(SC*n+1);
	vector<vi> ng(size(graph));
	vi inc(SC*n+1, 0);
	vi typ(size(graph));
	typ.back() = 0;
	for (int i = 0; i < SC*n; i++) {
		typ[i] = a[i/SC];
	}
	for (int k = 0; k < size(u); k++) {
		for (int i = 0; i < SC; i++) {
			int to = i;
			if (v[k] == chargingStation) {
				to++;
			}
			int toNode = v[k]*SC+to;
			if (to == SC) toNode = size(graph)-1;
			graph[toNode].push_back(u[k]*SC+i);
			ng[u[k]*SC+i].push_back(toNode);
			inc[u[k]*SC+i]++;
		}
	}
	vector<int> win(size(graph), 0);
	for (int i = 0; i < size(graph); i++) win[i] = false;
	queue<int> q;
	q.push(size(graph)-1);
	win[size(graph)-1] = true;
	while (!q.empty()) {
		int x = q.front();
		q.pop();
		for (int y : graph[x]) {
			if (typ[y] == 1) {
				if (!win[y]) {
					q.push(y);
					win[y] = true;
				}
			}
			else {
				inc[y]--;
				assert(inc[y] >= 0);
				if (inc[y] == 0) {
					assert(!win[y]);
					q.push(y);
					win[y] = true;
				}
			}
		}
	}
	vi fin(n);
	for (int i = 0; i < n; i++) fin[i] = win[i*SC+1];
	return fin;
}
# Verdict Execution time Memory Grader output
1 Runtime error 108 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 108 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 106 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 101 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 108 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -