#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"
const int N = 3e3 + 9 , mod = 1e9 + 7;
bool a[N][1009][2] ;
int b[N][1009][2] , ind = 0;
vector<int>v[7000009];
int n , k;
int ans = 0 , ind1 = 0;
vector<int>v1;
void get(int x , int y , int f){
a[x][y][f] = 1;
int m = b[x][y][f];
for(auto to : v[m])
if(!a[to][y][f])
get(to , y , f);
v[m].clear();
b[x][y][f] = 0;
v1.pb(m);
}
void add(int x , int y , int f , int p){
if(b[x][y][f] == 0){
if(ind < 7e6)
b[x][y][f] = ++ind;
else
b[x][y][f] = v1[ind1] , ind1++;
}
v[b[x][y][f]].pb(p);
}
void init(int n, int k){
::n = n , ::k = k;
for(int i = 1; i <= k; i++)
a[i][i][0] = a[i][i][1] = 1;
for(int i = 1; i < k; i++){
for(int j = 1; j <= k; j++){
if(!a[i + 1][j][0])
add(i , j , 0 , i + 1);
if(!a[i][j][1])
add(i + 1 , j , 1 , i);
if(a[i][j][0])
get(i , j ,0);
if(a[i + 1][j][1])
get(i + 1,j , 1);
}
}
}
int add_teleporter(int x , int y){
if(ans == 1)
return ans;
x++ , y++;
for(int i = 1; i <= k; i++){
if(!a[y][i][0])
add(x , i , 0 , y);
if(!a[x][i][1])
add(y , i , 1 , x );
if(a[x][i][0] && a[y][i][1])
ans = 1;
if(a[x][i][0])
get(x , i , 0);
if(a[y][i][1])
get(y , i , 1);
}
return ans;
}
/*
int main(){
TL;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
init(6 , 3);
cout<<add_teleporter(3 , 4)<<"\n";
cout<<add_teleporter(5 , 0)<<"\n";
cout<<add_teleporter(4 , 5)<<"\n";
cout<<add_teleporter(5 , 3)<<"\n";
cout<<add_teleporter(1 , 4)<<"\n";
}*/
// Author : حسن
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
164824 KB |
Output is correct |
2 |
Correct |
40 ms |
164696 KB |
Output is correct |
3 |
Correct |
42 ms |
166420 KB |
Output is correct |
4 |
Correct |
40 ms |
165400 KB |
Output is correct |
5 |
Correct |
40 ms |
166356 KB |
Output is correct |
6 |
Correct |
44 ms |
166224 KB |
Output is correct |
7 |
Correct |
43 ms |
166356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
164824 KB |
Output is correct |
2 |
Correct |
40 ms |
164696 KB |
Output is correct |
3 |
Correct |
42 ms |
166420 KB |
Output is correct |
4 |
Correct |
40 ms |
165400 KB |
Output is correct |
5 |
Correct |
40 ms |
166356 KB |
Output is correct |
6 |
Correct |
44 ms |
166224 KB |
Output is correct |
7 |
Correct |
43 ms |
166356 KB |
Output is correct |
8 |
Correct |
41 ms |
164712 KB |
Output is correct |
9 |
Correct |
39 ms |
164696 KB |
Output is correct |
10 |
Correct |
40 ms |
164828 KB |
Output is correct |
11 |
Correct |
40 ms |
165208 KB |
Output is correct |
12 |
Correct |
40 ms |
165464 KB |
Output is correct |
13 |
Correct |
42 ms |
165456 KB |
Output is correct |
14 |
Correct |
42 ms |
165720 KB |
Output is correct |
15 |
Correct |
40 ms |
165464 KB |
Output is correct |
16 |
Correct |
41 ms |
165464 KB |
Output is correct |
17 |
Correct |
42 ms |
165796 KB |
Output is correct |
18 |
Correct |
42 ms |
165720 KB |
Output is correct |
19 |
Correct |
43 ms |
165720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
164824 KB |
Output is correct |
2 |
Correct |
40 ms |
164696 KB |
Output is correct |
3 |
Correct |
42 ms |
166420 KB |
Output is correct |
4 |
Correct |
40 ms |
165400 KB |
Output is correct |
5 |
Correct |
40 ms |
166356 KB |
Output is correct |
6 |
Correct |
44 ms |
166224 KB |
Output is correct |
7 |
Correct |
43 ms |
166356 KB |
Output is correct |
8 |
Correct |
41 ms |
164712 KB |
Output is correct |
9 |
Correct |
39 ms |
164696 KB |
Output is correct |
10 |
Correct |
40 ms |
164828 KB |
Output is correct |
11 |
Correct |
40 ms |
165208 KB |
Output is correct |
12 |
Correct |
40 ms |
165464 KB |
Output is correct |
13 |
Correct |
42 ms |
165456 KB |
Output is correct |
14 |
Correct |
42 ms |
165720 KB |
Output is correct |
15 |
Correct |
40 ms |
165464 KB |
Output is correct |
16 |
Correct |
41 ms |
165464 KB |
Output is correct |
17 |
Correct |
42 ms |
165796 KB |
Output is correct |
18 |
Correct |
42 ms |
165720 KB |
Output is correct |
19 |
Correct |
43 ms |
165720 KB |
Output is correct |
20 |
Correct |
43 ms |
169416 KB |
Output is correct |
21 |
Correct |
45 ms |
168280 KB |
Output is correct |
22 |
Correct |
64 ms |
178124 KB |
Output is correct |
23 |
Correct |
45 ms |
170448 KB |
Output is correct |
24 |
Correct |
163 ms |
210108 KB |
Output is correct |
25 |
Correct |
107 ms |
193720 KB |
Output is correct |
26 |
Correct |
84 ms |
181436 KB |
Output is correct |
27 |
Correct |
152 ms |
216920 KB |
Output is correct |
28 |
Correct |
133 ms |
208564 KB |
Output is correct |
29 |
Correct |
158 ms |
213924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
164824 KB |
Output is correct |
2 |
Correct |
40 ms |
164696 KB |
Output is correct |
3 |
Correct |
42 ms |
166420 KB |
Output is correct |
4 |
Correct |
40 ms |
165400 KB |
Output is correct |
5 |
Correct |
40 ms |
166356 KB |
Output is correct |
6 |
Correct |
44 ms |
166224 KB |
Output is correct |
7 |
Correct |
43 ms |
166356 KB |
Output is correct |
8 |
Correct |
41 ms |
164712 KB |
Output is correct |
9 |
Correct |
39 ms |
164696 KB |
Output is correct |
10 |
Correct |
40 ms |
164828 KB |
Output is correct |
11 |
Correct |
40 ms |
165208 KB |
Output is correct |
12 |
Correct |
40 ms |
165464 KB |
Output is correct |
13 |
Correct |
42 ms |
165456 KB |
Output is correct |
14 |
Correct |
42 ms |
165720 KB |
Output is correct |
15 |
Correct |
40 ms |
165464 KB |
Output is correct |
16 |
Correct |
41 ms |
165464 KB |
Output is correct |
17 |
Correct |
42 ms |
165796 KB |
Output is correct |
18 |
Correct |
42 ms |
165720 KB |
Output is correct |
19 |
Correct |
43 ms |
165720 KB |
Output is correct |
20 |
Correct |
43 ms |
169416 KB |
Output is correct |
21 |
Correct |
45 ms |
168280 KB |
Output is correct |
22 |
Correct |
64 ms |
178124 KB |
Output is correct |
23 |
Correct |
45 ms |
170448 KB |
Output is correct |
24 |
Correct |
163 ms |
210108 KB |
Output is correct |
25 |
Correct |
107 ms |
193720 KB |
Output is correct |
26 |
Correct |
84 ms |
181436 KB |
Output is correct |
27 |
Correct |
152 ms |
216920 KB |
Output is correct |
28 |
Correct |
133 ms |
208564 KB |
Output is correct |
29 |
Correct |
158 ms |
213924 KB |
Output is correct |
30 |
Runtime error |
2307 ms |
262144 KB |
Execution killed with signal 9 |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
164824 KB |
Output is correct |
2 |
Correct |
40 ms |
164696 KB |
Output is correct |
3 |
Correct |
42 ms |
166420 KB |
Output is correct |
4 |
Correct |
40 ms |
165400 KB |
Output is correct |
5 |
Correct |
40 ms |
166356 KB |
Output is correct |
6 |
Correct |
44 ms |
166224 KB |
Output is correct |
7 |
Correct |
43 ms |
166356 KB |
Output is correct |
8 |
Correct |
41 ms |
164712 KB |
Output is correct |
9 |
Correct |
39 ms |
164696 KB |
Output is correct |
10 |
Correct |
40 ms |
164828 KB |
Output is correct |
11 |
Correct |
40 ms |
165208 KB |
Output is correct |
12 |
Correct |
40 ms |
165464 KB |
Output is correct |
13 |
Correct |
42 ms |
165456 KB |
Output is correct |
14 |
Correct |
42 ms |
165720 KB |
Output is correct |
15 |
Correct |
40 ms |
165464 KB |
Output is correct |
16 |
Correct |
41 ms |
165464 KB |
Output is correct |
17 |
Correct |
42 ms |
165796 KB |
Output is correct |
18 |
Correct |
42 ms |
165720 KB |
Output is correct |
19 |
Correct |
43 ms |
165720 KB |
Output is correct |
20 |
Correct |
43 ms |
169416 KB |
Output is correct |
21 |
Correct |
45 ms |
168280 KB |
Output is correct |
22 |
Correct |
64 ms |
178124 KB |
Output is correct |
23 |
Correct |
45 ms |
170448 KB |
Output is correct |
24 |
Correct |
163 ms |
210108 KB |
Output is correct |
25 |
Correct |
107 ms |
193720 KB |
Output is correct |
26 |
Correct |
84 ms |
181436 KB |
Output is correct |
27 |
Correct |
152 ms |
216920 KB |
Output is correct |
28 |
Correct |
133 ms |
208564 KB |
Output is correct |
29 |
Correct |
158 ms |
213924 KB |
Output is correct |
30 |
Runtime error |
2307 ms |
262144 KB |
Execution killed with signal 9 |
31 |
Halted |
0 ms |
0 KB |
- |