Submission #781218

# Submission time Handle Problem Language Result Execution time Memory
781218 2023-07-12T23:47:38 Z GusterGoose27 Toy Train (IOI17_train) C++17
11 / 100
8 ms 1876 KB
#include "train.h"

#include <bits/stdc++.h>

const int MAXN = 5005;
using namespace std;
vector<int> edges[MAXN];
vector<int> rev[MAXN];
int deg[MAXN];
bool owner[MAXN]; // 0 b, 1 a
vector<int> ans;
int n, m;

void activate(int cur) {
	if (ans[cur]) return; // r[i]
	assert(!ans[cur]);
	ans[cur] = 1;
	for (int v: rev[cur]) {
		deg[v]++;
		if ((deg[v] == 1 && owner[v]) || (deg[v] == edges[v].size() && !owner[v])) activate(v);
	}
}

void deactivate(int cur) {
	assert(ans[cur]);
	ans[cur] = 0;
	for (int v: rev[cur]) {
		deg[v]--;
		if ((deg[v] == 0 && owner[v]) || (deg[v] == edges[v].size()-1 && !owner[v])) deactivate(v);
	}
}

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++) owner[i] = a[i];
	for (int i = 0; i < m; i++) {
		edges[u[i]].push_back(v[i]);
		rev[v[i]].push_back(u[i]);
	}
	ans = vector<int>(n, 0);
	for (int i = 0; i < n; i++) {
		if (r[i]) activate(i);
	}
	for (int i = 0; i < n; i++) {
		if (ans[i] && ((deg[i] == 0 && owner[i]) || (deg[i] < edges[i].size() && !owner[i]))) {
			assert(r[i]);
			deactivate(i);
		}
	}
	return ans;
}

Compilation message

train.cpp: In function 'void activate(int)':
train.cpp:20:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   if ((deg[v] == 1 && owner[v]) || (deg[v] == edges[v].size() && !owner[v])) activate(v);
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~~
train.cpp: In function 'void deactivate(int)':
train.cpp:29:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   if ((deg[v] == 0 && owner[v]) || (deg[v] == edges[v].size()-1 && !owner[v])) deactivate(v);
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:46:55: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   if (ans[i] && ((deg[i] == 0 && owner[i]) || (deg[i] < edges[i].size() && !owner[i]))) {
      |                                                ~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1108 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Incorrect 1 ms 544 KB 3rd lines differ - on the 4th token, expected: '0', found: '1'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1876 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1364 KB Output is correct
2 Correct 5 ms 1424 KB Output is correct
3 Correct 6 ms 1576 KB Output is correct
4 Correct 6 ms 1492 KB Output is correct
5 Correct 6 ms 1620 KB Output is correct
6 Correct 6 ms 1620 KB Output is correct
7 Correct 6 ms 1492 KB Output is correct
8 Correct 8 ms 1556 KB Output is correct
9 Correct 6 ms 1412 KB Output is correct
10 Correct 6 ms 1620 KB Output is correct
11 Correct 6 ms 1580 KB Output is correct
12 Correct 6 ms 1620 KB Output is correct
13 Correct 6 ms 1612 KB Output is correct
14 Correct 6 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1620 KB Output is correct
2 Correct 6 ms 1620 KB Output is correct
3 Correct 8 ms 1568 KB Output is correct
4 Correct 6 ms 1492 KB Output is correct
5 Correct 1 ms 548 KB Output is correct
6 Correct 3 ms 1108 KB Output is correct
7 Correct 4 ms 1236 KB Output is correct
8 Incorrect 4 ms 1192 KB 3rd lines differ - on the 5th token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1108 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -