# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
975713 |
2024-05-05T18:54:12 Z |
ShaShi |
Game (APIO22_game) |
C++17 |
|
13 ms |
51696 KB |
#include "game.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
using namespace std;
typedef long long ll;
const int MAXN = (int)1e6 + 7;
const int LG = 60;
int dp[MAXN], pd[MAXN];
vector<int> adj[MAXN][2];
bool seen[MAXN], flag;
int N, K, X;
bool check(int x) {
if (dp[x] <= pd[x]) return 1;
return 0;
}
void init(int n, int k) {
N = n;
K = k;
for (int i=0; i<N; i++) dp[i] = pd[i] = -1;
fill(seen, seen+N+1, 1);
}
void DFS(int v, bool b) {
if (flag) return;
seen[v] = 1;
if (b) dp[v] = (dp[v] == -1? X : min(dp[v], X));
else pd[v] = (pd[v] == -1? X : max(pd[v], X));
if (dp[v] != -1 && pd[v] != -1 && dp[v] <= pd[v]) flag = 1;
for (int u:adj[v][b]) if (!seen[u]) DFS(u, b);
}
int add_teleporter(int u, int v) {
if (u < K && v < K) {
if (u >= v) return 1;
return 0;
}
fill(seen+K+1, seen+N+1, 0);
flag = 0;
if (u < K) {
X = u;
DFS(v, 0);
} else if (v < K) {
X = v;
DFS(u, 1);
} else {
adj[u][0].pb(v); adj[v][1].pb(u);
X = pd[u];
DFS(u, 0);
}
// for (int i=K; i<N; i++) if (dp[i] != -1 && pd[i] != -1 && dp[i] <= pd[i]) return 1
return flag;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
51544 KB |
Output is correct |
2 |
Correct |
13 ms |
51544 KB |
Output is correct |
3 |
Correct |
11 ms |
51544 KB |
Output is correct |
4 |
Correct |
11 ms |
51544 KB |
Output is correct |
5 |
Correct |
11 ms |
51544 KB |
Output is correct |
6 |
Correct |
11 ms |
51696 KB |
Output is correct |
7 |
Correct |
11 ms |
51544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
51544 KB |
Output is correct |
2 |
Correct |
13 ms |
51544 KB |
Output is correct |
3 |
Correct |
11 ms |
51544 KB |
Output is correct |
4 |
Correct |
11 ms |
51544 KB |
Output is correct |
5 |
Correct |
11 ms |
51544 KB |
Output is correct |
6 |
Correct |
11 ms |
51696 KB |
Output is correct |
7 |
Correct |
11 ms |
51544 KB |
Output is correct |
8 |
Correct |
11 ms |
51544 KB |
Output is correct |
9 |
Correct |
11 ms |
51544 KB |
Output is correct |
10 |
Incorrect |
13 ms |
51544 KB |
Wrong Answer[1] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
51544 KB |
Output is correct |
2 |
Correct |
13 ms |
51544 KB |
Output is correct |
3 |
Correct |
11 ms |
51544 KB |
Output is correct |
4 |
Correct |
11 ms |
51544 KB |
Output is correct |
5 |
Correct |
11 ms |
51544 KB |
Output is correct |
6 |
Correct |
11 ms |
51696 KB |
Output is correct |
7 |
Correct |
11 ms |
51544 KB |
Output is correct |
8 |
Correct |
11 ms |
51544 KB |
Output is correct |
9 |
Correct |
11 ms |
51544 KB |
Output is correct |
10 |
Incorrect |
13 ms |
51544 KB |
Wrong Answer[1] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
51544 KB |
Output is correct |
2 |
Correct |
13 ms |
51544 KB |
Output is correct |
3 |
Correct |
11 ms |
51544 KB |
Output is correct |
4 |
Correct |
11 ms |
51544 KB |
Output is correct |
5 |
Correct |
11 ms |
51544 KB |
Output is correct |
6 |
Correct |
11 ms |
51696 KB |
Output is correct |
7 |
Correct |
11 ms |
51544 KB |
Output is correct |
8 |
Correct |
11 ms |
51544 KB |
Output is correct |
9 |
Correct |
11 ms |
51544 KB |
Output is correct |
10 |
Incorrect |
13 ms |
51544 KB |
Wrong Answer[1] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
51544 KB |
Output is correct |
2 |
Correct |
13 ms |
51544 KB |
Output is correct |
3 |
Correct |
11 ms |
51544 KB |
Output is correct |
4 |
Correct |
11 ms |
51544 KB |
Output is correct |
5 |
Correct |
11 ms |
51544 KB |
Output is correct |
6 |
Correct |
11 ms |
51696 KB |
Output is correct |
7 |
Correct |
11 ms |
51544 KB |
Output is correct |
8 |
Correct |
11 ms |
51544 KB |
Output is correct |
9 |
Correct |
11 ms |
51544 KB |
Output is correct |
10 |
Incorrect |
13 ms |
51544 KB |
Wrong Answer[1] |
11 |
Halted |
0 ms |
0 KB |
- |