Submission #806731

# Submission time Handle Problem Language Result Execution time Memory
806731 2023-08-04T09:17:15 Z ymm Toy Train (IOI17_train) C++17
28 / 100
130 ms 1540 KB
%:include "train.h"
%:include <bits/stdc++.h>
%:define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
%:define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 5050;
bool rem[N];
bool owner[N];
bool charg[N];
int deg[N];
vector<int> T[N];
vector<int> V;

void remove(const vector<int> &vec)
{
	for (int v : vec)
		rem[v] = 1;
	Loop (i,0,V.size()) {
		if (rem[V[i]]) {
			swap(V[i], V.back());
			V.pop_back();
			--i;
		}
	}
	for (int v : V) {
		Loop (i,0,T[v].size()) {
			if (rem[T[v][i]]) {
				swap(T[v][i], T[v].back());
				T[v].pop_back();
				--i;
			}
		}
	}
}

int cnt[N];
bool vis[N];
void dfs(int v, bool o)
{
	vis[v] = 1;
	for (int u : T[v]) {
		++cnt[u];
		if (!vis[u] && (owner[u] == o || cnt[u] == deg[u]))
			dfs(u, o);
	}
}
vector<int> f(const vector<int> &vec, bool o)
{
	for (int v : vec) {
		if (!rem[v] && !vis[v])
			dfs(v, o);
	}
	vector<int> ans;
	for (int v : V) {
		if (vis[v])
			ans.push_back(v);
		vis[v] = 0;
		cnt[v] = 0;
	}
	return ans;
}

vector<int> cmpl(const vector<int> &vec)
{
	vector<int> ans;
	static bool a[N];
	for (int v : vec)
		a[v] = 1;
	for (int v : V) {
		if (!a[v])
			ans.push_back(v);
	}
	for (int v : vec)
		a[v] = 0;
	return ans;
}

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> vv, std::vector<int> uu)
{
	int n = a.size();
	V.resize(n);
	iota(V.begin(), V.end(), 0);
	vector<int> charg;
	Loop (i,0,n) {
		owner[i] = a[i];
		if (r[i])
			charg.push_back(i);
	}
	Loop (i,0,vv.size()) {
		int v = vv[i], u = uu[i];
		deg[v]++;
		T[u].push_back(v);
	}
	vector<int> ans;
	for (;;) {
		auto vec = f(charg, 1);
		if (vec.size() == V.size()) {
			ans = V;
			break;
		}
		if (vec.size() == 0)
			break;
		auto vec2 = f(cmpl(vec), 0);
		remove(vec2);
	}
	vector<int> res(n);
	for (int v : ans)
		res[v] = 1;
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 4 ms 980 KB Output is correct
3 Correct 4 ms 980 KB Output is correct
4 Correct 4 ms 1108 KB Output is correct
5 Correct 4 ms 980 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 4 ms 956 KB Output is correct
8 Correct 4 ms 932 KB Output is correct
9 Correct 3 ms 976 KB Output is correct
10 Correct 4 ms 852 KB Output is correct
11 Correct 3 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Incorrect 1 ms 468 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 1540 KB Output is correct
2 Correct 107 ms 1536 KB Output is correct
3 Correct 130 ms 1532 KB Output is correct
4 Correct 6 ms 1364 KB Output is correct
5 Incorrect 6 ms 1468 KB 3rd lines differ - on the 11th token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 968 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 5 ms 1340 KB Output is correct
4 Correct 6 ms 1340 KB Output is correct
5 Correct 6 ms 1364 KB Output is correct
6 Correct 5 ms 1368 KB Output is correct
7 Correct 6 ms 1236 KB Output is correct
8 Correct 5 ms 1240 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 6 ms 1340 KB Output is correct
11 Correct 6 ms 1392 KB Output is correct
12 Correct 5 ms 1364 KB Output is correct
13 Correct 6 ms 1364 KB Output is correct
14 Correct 6 ms 1252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1236 KB Output is correct
2 Correct 6 ms 1492 KB Output is correct
3 Correct 8 ms 1364 KB Output is correct
4 Correct 5 ms 1236 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 4 ms 980 KB Output is correct
8 Correct 4 ms 1080 KB Output is correct
9 Correct 4 ms 980 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 4 ms 952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 4 ms 980 KB Output is correct
3 Correct 4 ms 980 KB Output is correct
4 Correct 4 ms 1108 KB Output is correct
5 Correct 4 ms 980 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 4 ms 956 KB Output is correct
8 Correct 4 ms 932 KB Output is correct
9 Correct 3 ms 976 KB Output is correct
10 Correct 4 ms 852 KB Output is correct
11 Correct 3 ms 956 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 436 KB Output is correct
19 Incorrect 1 ms 468 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
20 Halted 0 ms 0 KB -