Submission #981525

# Submission time Handle Problem Language Result Execution time Memory
981525 2024-05-13T09:52:31 Z c2zi6 Game (APIO22_game) C++17
30 / 100
4000 ms 2808 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "game.h"

int n, k;
VVI gp;
VVI trans;

void init(int N, int K) {n = N, k = K;
	trans = gp = VVI(n);
	replr(i, 0, k-2) {
		gp[i].pb(i+1);
		trans[i+1].pb(i);
	}
}

VI order;
VI vis;
void dfs1(int u) {
	vis[u] = true;
	for (int v : gp[u]) if (!vis[v]) dfs1(v);
	order.pb(u);
}
VI group;
void dfs2(int u, int g) {
	group[u] = g;
	vis[u] = true;
	for (int v : trans[u]) if (!vis[v]) dfs2(v, g);
}

int add_teleporter(int u, int v) {
	if (u == v) {
		if (u < k) return 1;
		return 0;
	}

	gp[u].pb(v);
	trans[v].pb(u);

	order.clear();
	vis = VI(n);
	rep(u, n) if (!vis[u]) dfs1(u);
	reverse(all(order));
	vis = VI(n);
	int g = 0;
	group = VI(n);
	for (int u : order) if (!vis[u]) dfs2(u, g++);
	/* rep(u, n) { */
	/* 	cout << "NODE " << u << " HAS GROUP " << group[u] << endl; */
	/* } */
	/* cout << endl; */

	VI ka(g);
	rep(u, n) ka[group[u]]++;
	rep(u, k) if (ka[group[u]] > 1) return true;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 596 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 596 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 11 ms 600 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 12 ms 552 KB Output is correct
23 Correct 14 ms 600 KB Output is correct
24 Correct 15 ms 344 KB Output is correct
25 Correct 76 ms 804 KB Output is correct
26 Correct 79 ms 344 KB Output is correct
27 Correct 67 ms 344 KB Output is correct
28 Correct 34 ms 344 KB Output is correct
29 Correct 65 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 596 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 11 ms 600 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 12 ms 552 KB Output is correct
23 Correct 14 ms 600 KB Output is correct
24 Correct 15 ms 344 KB Output is correct
25 Correct 76 ms 804 KB Output is correct
26 Correct 79 ms 344 KB Output is correct
27 Correct 67 ms 344 KB Output is correct
28 Correct 34 ms 344 KB Output is correct
29 Correct 65 ms 344 KB Output is correct
30 Execution timed out 4014 ms 2808 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 596 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 11 ms 600 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 12 ms 552 KB Output is correct
23 Correct 14 ms 600 KB Output is correct
24 Correct 15 ms 344 KB Output is correct
25 Correct 76 ms 804 KB Output is correct
26 Correct 79 ms 344 KB Output is correct
27 Correct 67 ms 344 KB Output is correct
28 Correct 34 ms 344 KB Output is correct
29 Correct 65 ms 344 KB Output is correct
30 Execution timed out 4014 ms 2808 KB Time limit exceeded
31 Halted 0 ms 0 KB -