Submission #92446

# Submission time Handle Problem Language Result Execution time Memory
92446 2019-01-02T22:25:19 Z qkxwsm Toy Train (IOI17_train) C++14
16 / 100
79 ms 1152 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
#include "train.h"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

random_device(rd);
mt19937 rng(rd());
const long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();

struct custom_hash
{
	template<class T>
	unsigned long long operator()(T v) const
	{
		unsigned long long x = v;
		x += FIXED_RANDOM; x += 11400714819323198485ull;
		// x = (x ^ (x >> 30)) * 13787848793156543929ull;
		// x = (x ^ (x >> 27)) * 10723151780598845931ull;
		return x ^ (x >> 31);
	}
};

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, class U> using hash_table = gp_hash_table<T, U, custom_hash>;

template<class T>
T randomize(T mod)
{
	return (uniform_int_distribution<T>(0, mod - 1))(rng);
}
template<class T>
void ckmin(T &a, T b)
{
	a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
	a = max(a, b);
}
long long expo(long long a, long long e, long long mod)
{
	return ((e == 0) ? 1 : ((expo(a * a % mod, e >> 1, mod)) * ((e & 1) ? a : 1) % mod));
}
template<class T, class U>
T nmod(T &x, U mod)
{
	if (x >= mod) x -= mod;
}
template<class T>
T gcd(T a, T b)
{
	return (b ? gcd(b, a % b) : a);
}

#define y0 ___y0
#define y1 ___y1
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define fi first
#define se second
#define DBG(x) cerr << #x << " = " << x << endl;
#define SZ(x) ((int) (x.size()))
#define FOR(i, a, b) for (auto i = (a), i##__end__ = (b); i < i##__end__; i++)
#define FORD(i, a, b) for (auto i = (a) - 1, i##__end__ = (b); i >= i##__end__; i--)
#define ALL(x) x.begin(), x.end()

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-9;

#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 5013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pdd> vpd;

int N;
vi edge[MAXN];
bitset<MAXN> own, flag;
bitset<MAXN> inside;
vi ans;

vi who_wins(vi a, vi r, vi u, vi v)
{
	N = SZ(a); ans.resize(N);
	FOR(i, 0, N)
	{
		own[i] = a[i];
	}
	FOR(i, 0, N)
	{
		flag[i] = r[i];
	}
	FOR(i, 0, SZ(u))
	{
		edge[u[i]].PB(v[i]);
	}
	FOR(i, 0, N)
	{
		inside[i] = !(flag[i]);
	}
	// cerr << "insides:";
	// FOR(i, 0, N)
	// {
	// 	cerr << ' ' << inside[i];
	// }
	// cerr << endl;
	bool change = true;
	while(change)
	{
		change = false;
		FOR(u, 0, N)
		{
			if (!inside[u]) continue;
			if (own[u])
			{
				for (int v : edge[u])
				{
					if (!inside[v])
					{
						inside[u] = false;
						change = true;
					}
				}
			}
			else
			{
				bool ok = false;
				for (int v : edge[u])
				{
					if (inside[v]) ok = true;
				}
				if (!ok)
				{
					// if (u == 8) cerr << "fuck\n";
					inside[u] = false;
					change = true;
				}
			}
		}
	}
	// cerr << "insides:";
	// FOR(i, 0, N)
	// {
	// 	cerr << ' ' << inside[i];
	// }
	// cerr << endl;
	// DBG(inside[8]);
	// DBG(inside[14]);
	//once you're inside the trap, you can never get out!
	FOR(i, 0, N)
	{
		ans[i] = (inside[i] ? 0 : 1);
	}
	change = true;
	while(change)
	{
		change = false;
		FOR(u, 0, N)
		{
			if (!ans[u]) continue;
			if (own[u])
			{
				bool ok = false;
				for (int v : edge[u])
				{
					if (ans[v] && (v != u || flag[u])) ok = true;
				}
				if (!ok)
				{
					ans[u] = 0;
					change = true;
				}
			}
			else
			{
				for (int v : edge[u])
				{
					if (!ans[v])
					{
						ans[u] = 0;
						change = true;
					}
				}
			}
		}
	}
	//if this is in S, then that must be in S
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 760 KB Output is correct
2 Correct 6 ms 888 KB Output is correct
3 Correct 6 ms 888 KB Output is correct
4 Correct 7 ms 888 KB Output is correct
5 Correct 6 ms 888 KB Output is correct
6 Correct 6 ms 884 KB Output is correct
7 Correct 6 ms 888 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 6 ms 888 KB Output is correct
10 Correct 5 ms 892 KB Output is correct
11 Correct 5 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Incorrect 2 ms 504 KB 3rd lines differ - on the 3rd token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 1144 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 7 ms 1016 KB Output is correct
2 Correct 10 ms 1016 KB Output is correct
3 Correct 10 ms 1144 KB Output is correct
4 Correct 9 ms 1144 KB Output is correct
5 Correct 42 ms 1016 KB Output is correct
6 Correct 68 ms 1016 KB Output is correct
7 Correct 36 ms 1016 KB Output is correct
8 Correct 10 ms 1068 KB Output is correct
9 Correct 7 ms 1016 KB Output is correct
10 Correct 8 ms 1144 KB Output is correct
11 Correct 8 ms 1152 KB Output is correct
12 Correct 8 ms 1144 KB Output is correct
13 Correct 11 ms 1144 KB Output is correct
14 Correct 10 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1016 KB Output is correct
2 Correct 9 ms 1060 KB Output is correct
3 Correct 10 ms 1064 KB Output is correct
4 Correct 8 ms 1016 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 6 ms 888 KB Output is correct
8 Incorrect 6 ms 888 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 Correct 6 ms 760 KB Output is correct
2 Correct 6 ms 888 KB Output is correct
3 Correct 6 ms 888 KB Output is correct
4 Correct 7 ms 888 KB Output is correct
5 Correct 6 ms 888 KB Output is correct
6 Correct 6 ms 884 KB Output is correct
7 Correct 6 ms 888 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 6 ms 888 KB Output is correct
10 Correct 5 ms 892 KB Output is correct
11 Correct 5 ms 888 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Incorrect 2 ms 504 KB 3rd lines differ - on the 3rd token, expected: '0', found: '1'
17 Halted 0 ms 0 KB -