# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
983791 |
2024-05-16T06:12:11 Z |
Kenjikrab |
Game (APIO22_game) |
C++17 |
|
4 ms |
15192 KB |
#include "game.h"
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
int const n_max=3e5+10;
int mx[n_max],mn[n_max];
vector<int> node[n_max];
vector<int> rnode[n_max];
int n,k;
void init(int N, int K)
{
n=N;
k=K;
for(int i=1;i<=k;i++)mx[i]=mn[i]=i;
for(int i=k+1;i<=n;i++)mx[i]=0,mn[i]=k+1;
}
bool flag=false;
int add_teleporter(int uu, int vv)
{
uu++;
vv++;
if(flag)return 1;
if (uu >= vv && uu <= k){flag=true;return 1;}
if (uu == vv) return 0;
node[uu].push_back(vv);
rnode[vv].push_back(uu);
deque<pii> q;
q.push_front({uu,vv});
while(!q.empty())
{
int u=q.front().fi,v=q.front().se;
q.pop_front();
if(mx[u]>=mn[v])
{
flag=true;
return 1;
}
if(mn[u]<=mx[v])
{
continue;
}
while (mx[u] >= (mn[v] + mx[v]) / 2+1)
{
mx[v] = (mx[v] + mn[v]) / 2+1;
for (auto it:node[v])
{
q.push_front({v,it});
}
}
while (mn[v] <= (mn[u] + mx[u]) / 2)
{
mn[u] = (mx[u] + mn[u]) / 2 ;
for (auto it:rnode[v])
{
q.push_front({it,u});
}
if(mn[u]==0)return 1;
}
}
if(flag)return 1;
return 0;
/* queue<int> q;
int val=mx[u];
if(u<k)val=u;
if(val==-1)return 0;
q.push(v);
while(!q.empty())
{
int cur=q.front();
q.pop();
if(mx[cur]>=val)continue;
if(cur<k&&val>=cur)
{
flag=true;
return 1;
}
mx[cur]=val;
for(auto nxt:node[cur])
{
if(mx[nxt]>=val)continue;
q.push(nxt);
}
}
return 0; */
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
3 ms |
14936 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14936 KB |
Output is correct |
6 |
Correct |
3 ms |
14936 KB |
Output is correct |
7 |
Correct |
3 ms |
15192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
3 ms |
14936 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14936 KB |
Output is correct |
6 |
Correct |
3 ms |
14936 KB |
Output is correct |
7 |
Correct |
3 ms |
15192 KB |
Output is correct |
8 |
Correct |
3 ms |
14932 KB |
Output is correct |
9 |
Correct |
4 ms |
14936 KB |
Output is correct |
10 |
Correct |
3 ms |
14936 KB |
Output is correct |
11 |
Correct |
3 ms |
14936 KB |
Output is correct |
12 |
Correct |
3 ms |
14936 KB |
Output is correct |
13 |
Incorrect |
3 ms |
14936 KB |
Wrong Answer[1] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
3 ms |
14936 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14936 KB |
Output is correct |
6 |
Correct |
3 ms |
14936 KB |
Output is correct |
7 |
Correct |
3 ms |
15192 KB |
Output is correct |
8 |
Correct |
3 ms |
14932 KB |
Output is correct |
9 |
Correct |
4 ms |
14936 KB |
Output is correct |
10 |
Correct |
3 ms |
14936 KB |
Output is correct |
11 |
Correct |
3 ms |
14936 KB |
Output is correct |
12 |
Correct |
3 ms |
14936 KB |
Output is correct |
13 |
Incorrect |
3 ms |
14936 KB |
Wrong Answer[1] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
3 ms |
14936 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14936 KB |
Output is correct |
6 |
Correct |
3 ms |
14936 KB |
Output is correct |
7 |
Correct |
3 ms |
15192 KB |
Output is correct |
8 |
Correct |
3 ms |
14932 KB |
Output is correct |
9 |
Correct |
4 ms |
14936 KB |
Output is correct |
10 |
Correct |
3 ms |
14936 KB |
Output is correct |
11 |
Correct |
3 ms |
14936 KB |
Output is correct |
12 |
Correct |
3 ms |
14936 KB |
Output is correct |
13 |
Incorrect |
3 ms |
14936 KB |
Wrong Answer[1] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
3 ms |
14936 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14936 KB |
Output is correct |
6 |
Correct |
3 ms |
14936 KB |
Output is correct |
7 |
Correct |
3 ms |
15192 KB |
Output is correct |
8 |
Correct |
3 ms |
14932 KB |
Output is correct |
9 |
Correct |
4 ms |
14936 KB |
Output is correct |
10 |
Correct |
3 ms |
14936 KB |
Output is correct |
11 |
Correct |
3 ms |
14936 KB |
Output is correct |
12 |
Correct |
3 ms |
14936 KB |
Output is correct |
13 |
Incorrect |
3 ms |
14936 KB |
Wrong Answer[1] |
14 |
Halted |
0 ms |
0 KB |
- |