Submission #765293

# Submission time Handle Problem Language Result Execution time Memory
765293 2023-06-24T10:28:54 Z marvinthang Toy Train (IOI17_train) C++17
28 / 100
190 ms 1564 KB
/*************************************
*    author: marvinthang             *
*    created: 24.06.2023 17:13:38    *
*************************************/

#include "train.h"
#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define              ALL(v)  (v).begin(), (v).end()
#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          REPD(i, n)  for (int i = (n); i--; )
#define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i) 
#define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; ) 
#define       FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define      FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i) 
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
    #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

// end of template

vector <int> who_wins(vector <int> a, vector <int> r, vector <int> u, vector <int> v) {
	int n = a.size();
	int m = u.size();
	vector <vector <int>> radj(n);
	vector <int> deg(n);
	REP(i, m) {
		radj[v[i]].push_back(u[i]);
	}
	vector <bool> visited(n, false);
	vector <int> blocked(n, false);
	while (true) {
		copy(ALL(blocked), visited.begin());
		function <void(int, int)> dfs = [&] (int u, int t) {
			visited[u] = true;
			for (int v: radj[u]) if (!visited[v] && (a[v] == t || !--deg[v])) dfs(v, t);
		};
		fill(ALL(deg), 0);
		REP(i, m) ++deg[u[i]];
		REP(i, n) if (r[i] && !visited[i]) dfs(i, 1);
		vector <int> rem;
		REP(i, n) if (!visited[i]) rem.push_back(i);
		if (rem.empty()) break;
		copy(ALL(blocked), visited.begin());
		for (int u: rem) if (!visited[u]) dfs(u, 0);
		REP(i, n) if (visited[i]) blocked[i] = true;
	}
	REP(i, n) blocked[i] ^= 1;
	return blocked;
}

#ifdef LOCAL
#include "train.h"

#include <cstdio>
#include <vector>
#include <cassert>

using namespace std;

int main() {
	file("train");
	int n, m;
	assert(2 == scanf("%d %d", &n, &m));

	vector<int> a(n), r(n), u(m), v(m);

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &a[i]));

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &r[i]));

	for(int i = 0; i < m; i++)
		assert(2 == scanf("%d %d", &u[i], &v[i]));

	vector<int> res = who_wins(a, r, u, v);

	for(int i = 0; i < (int)res.size(); i++)
		printf(i ? " %d" : "%d", res[i]);
	printf("\n");

	return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 4 ms 852 KB Output is correct
2 Correct 4 ms 824 KB Output is correct
3 Correct 3 ms 824 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 3 ms 820 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 3 ms 824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Incorrect 1 ms 292 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 66 ms 1504 KB Output is correct
2 Correct 138 ms 1560 KB Output is correct
3 Correct 190 ms 1564 KB Output is correct
4 Correct 5 ms 1364 KB Output is correct
5 Incorrect 9 ms 1404 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 948 KB Output is correct
2 Correct 5 ms 1108 KB Output is correct
3 Correct 6 ms 1236 KB Output is correct
4 Correct 5 ms 1208 KB Output is correct
5 Correct 6 ms 1236 KB Output is correct
6 Correct 6 ms 1236 KB Output is correct
7 Correct 5 ms 1236 KB Output is correct
8 Correct 5 ms 1232 KB Output is correct
9 Correct 5 ms 1108 KB Output is correct
10 Correct 5 ms 1236 KB Output is correct
11 Correct 6 ms 1244 KB Output is correct
12 Correct 6 ms 1212 KB Output is correct
13 Correct 6 ms 1364 KB Output is correct
14 Correct 5 ms 1212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1236 KB Output is correct
2 Correct 5 ms 1372 KB Output is correct
3 Correct 5 ms 1236 KB Output is correct
4 Correct 5 ms 1236 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 3 ms 812 KB Output is correct
8 Correct 4 ms 852 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
11 Correct 3 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 852 KB Output is correct
2 Correct 4 ms 824 KB Output is correct
3 Correct 3 ms 824 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 3 ms 820 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 3 ms 824 KB Output is correct
12 Correct 0 ms 300 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Incorrect 1 ms 292 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
20 Halted 0 ms 0 KB -