# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
518539 | 2022-01-24T04:09:24 Z | thegrimbee | Experimental Charges (NOI19_charges) | C++14 | 36 ms | 4848 KB |
#include <bits/stdc++.h> #define int long long using namespace std; int p[2*1000005]; ///parent int height[1000005]; ///height void reset(int N){ for(int i = 0;i <= N;i++){ p[i] = i; ///all sets are disjoint height[i] = 1; } } int findSet(int u){ if(u == p[u]) return u; ///representative else{ p[u] = findSet(p[u]); ///search upwards return p[u]; } } void unionSet(int a, int b){ ///find represenative of a and b int A = findSet(a); int B = findSet(b); if(A == B) return; if(height[A] < height[B]){ p[A] = B; } else{ p[B] = A; if(height[A] == height[B]) height[A]++; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int N, Q; char T; int a , b, temp1, temp2, temp3, temp4; cin >> N >> Q; reset(2*(N+1)); for (int i = 0; i < Q; ++i){ cin >> T >> a >> b; if (T == 'Q'){ temp1 = findSet(a); temp2 = findSet(b); temp3 = findSet(a+N); temp4 = findSet(b+N); if (temp1 == temp2 && temp1 == temp4)cout << "?\n"; else if (temp1 == temp2)cout << "R\n"; else if (temp1 == temp4)cout << "A\n"; else cout << "?\n"; } else if (T == 'A'){ unionSet(a, b + N); unionSet(a+N, b); } else{ unionSet(a, b); unionSet(a+N, b+N); } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 324 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 4172 KB | Output is correct |
2 | Correct | 19 ms | 4180 KB | Output is correct |
3 | Correct | 21 ms | 4172 KB | Output is correct |
4 | Correct | 21 ms | 4180 KB | Output is correct |
5 | Correct | 19 ms | 4176 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 4812 KB | Output is correct |
2 | Correct | 26 ms | 4712 KB | Output is correct |
3 | Correct | 23 ms | 4748 KB | Output is correct |
4 | Correct | 27 ms | 4676 KB | Output is correct |
5 | Correct | 27 ms | 4848 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 4552 KB | Output is correct |
2 | Correct | 23 ms | 4548 KB | Output is correct |
3 | Correct | 24 ms | 4444 KB | Output is correct |
4 | Correct | 24 ms | 4768 KB | Output is correct |
5 | Correct | 25 ms | 4588 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 324 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 324 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 19 ms | 4172 KB | Output is correct |
7 | Correct | 19 ms | 4180 KB | Output is correct |
8 | Correct | 21 ms | 4172 KB | Output is correct |
9 | Correct | 21 ms | 4180 KB | Output is correct |
10 | Correct | 19 ms | 4176 KB | Output is correct |
11 | Correct | 20 ms | 4812 KB | Output is correct |
12 | Correct | 26 ms | 4712 KB | Output is correct |
13 | Correct | 23 ms | 4748 KB | Output is correct |
14 | Correct | 27 ms | 4676 KB | Output is correct |
15 | Correct | 27 ms | 4848 KB | Output is correct |
16 | Correct | 21 ms | 4552 KB | Output is correct |
17 | Correct | 23 ms | 4548 KB | Output is correct |
18 | Correct | 24 ms | 4444 KB | Output is correct |
19 | Correct | 24 ms | 4768 KB | Output is correct |
20 | Correct | 25 ms | 4588 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 1 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 332 KB | Output is correct |
24 | Correct | 1 ms | 336 KB | Output is correct |
25 | Correct | 1 ms | 332 KB | Output is correct |
26 | Correct | 21 ms | 4640 KB | Output is correct |
27 | Correct | 25 ms | 4680 KB | Output is correct |
28 | Correct | 36 ms | 4460 KB | Output is correct |
29 | Correct | 32 ms | 4552 KB | Output is correct |
30 | Correct | 29 ms | 4564 KB | Output is correct |