# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259547 | cheeheng | Fishing Game (RMI19_fishing) | C++14 | 690 ms | 524292 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int cnt = 0;
void rec(set<int> A, set<int> B, set<int> C, int mode){
if(A.empty() && B.empty() && C.empty()){
cnt ++;
return;
}
if(mode == 0){
if(A.empty()){
rec(A, B, C, 1);
}else{
set<int> A2;
for(int x: A){
A2.insert(x);
}
set<int> B2;
for(int x: B){
B2.insert(x);
}
for(int x: A){
A2.erase(x);
if(B.find(x) != B.end()){
B2.erase(x);
rec(A2, B2, C, 1);
B2.insert(x);
}else{
B2.insert(x);
rec(A2, B2, C, 1);
B2.erase(x);
}
A2.insert(x);
}
}
}else if(mode == 1){
if(B.empty()){
rec(A, B, C, 2);
}else{
set<int> B2;
for(int x: B){
B.insert(x);
}
set<int> C2;
for(int x: C){
C2.insert(x);
}
for(int x: B){
B2.erase(x);
if(C.find(x) != C.end()){
C2.erase(x);
rec(A, B2, C2, 1);
C2.insert(x);
}else{
C2.insert(x);
rec(A, B2, C2, 1);
C2.erase(x);
}
B2.insert(x);
}
}
}else if(mode == 2){
if(C.empty()){
rec(A, B, C, 0);
}else{
set<int> C2;
for(int x: C){
C.insert(x);
}
set<int> A2;
for(int x: A){
A2.insert(x);
}
for(int x: C){
C2.erase(x);
if(A.find(x) != A.end()){
A2.erase(x);
rec(A2, B, C2, 1);
A2.insert(x);
}else{
A2.insert(x);
rec(A2, B, C2, 1);
A2.erase(x);
}
C2.insert(x);
}
}
}
}
int main(){
int N, T;
scanf("%d%d", &N, &T);
while(T --){
set<int> A;
set<int> B;
set<int> C;
for(int i = 0; i < 2*N; i ++){
int x;
scanf("%d", &x);
if(A.count(x)){
A.erase(x);
}else{
A.insert(x);
}
}
for(int i = 0; i < 2*N; i ++){
int x;
scanf("%d", &x);
if(B.count(x)){
B.erase(x);
}else{
B.insert(x);
}
}
for(int i = 0; i < 2*N; i ++){
int x;
scanf("%d", &x);
if(C.count(x)){
C.erase(x);
}else{
C.insert(x);
}
}
cnt = 0;
rec(A, B, C, 0);
printf("%d\n", cnt);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |