#include <bits/stdc++.h>
using namespace std;
int cnt = 0;
int recCnt = 0;
void rec(set<int> A, set<int> B, set<int> C, int mode, int numDiscarded){
recCnt ++;
//if(recCnt > 100){exit(0);}
if(mode == 0 && numDiscarded == 0){return;}
if(mode == 0){numDiscarded = 0;}
if(A.empty() && B.empty() && C.empty()){
cnt ++;
return;
}
/*printf("rec(mode = %d, numDiscarded = %d)\n", mode, numDiscarded);
for(int x: A){
printf("%d ", x);
}
printf("\n");
for(int x: B){
printf("%d ", x);
}
printf("\n");
for(int x: C){
printf("%d ", x);
}
printf("\n");*/
if(mode == 0){
if(A.empty()){
rec(A, B, C, 1, numDiscarded);
}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, numDiscarded+1);
B2.insert(x);
}else{
B2.insert(x);
rec(A2, B2, C, 1, numDiscarded);
B2.erase(x);
}
A2.insert(x);
}
}
}else if(mode == 1){
if(B.empty()){
rec(A, B, C, 2, numDiscarded);
}else{
set<int> B2;
for(int x: B){
B2.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, 2, numDiscarded+1);
C2.insert(x);
}else{
C2.insert(x);
rec(A, B2, C2, 2, numDiscarded);
C2.erase(x);
}
B2.insert(x);
}
}
}else if(mode == 2){
if(C.empty()){
rec(A, B, C, 0, numDiscarded);
}else{
set<int> C2;
for(int x: C){
C2.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, 0, numDiscarded+1);
A2.insert(x);
}else{
A2.insert(x);
rec(A2, B, C2, 0, numDiscarded);
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, 1);
printf("%d\n", cnt);
}
}
Compilation message
fishing.cpp: In function 'int main()':
fishing.cpp:116:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &T);
~~~~~^~~~~~~~~~~~~~~~
fishing.cpp:125:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &x);
~~~~~^~~~~~~~~~
fishing.cpp:135:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &x);
~~~~~^~~~~~~~~~
fishing.cpp:145:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &x);
~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
504 KB |
Output is correct |
2 |
Execution timed out |
2069 ms |
384 KB |
Time limit exceeded |
3 |
Execution timed out |
2081 ms |
384 KB |
Time limit exceeded |
4 |
Execution timed out |
2079 ms |
512 KB |
Time limit exceeded |
5 |
Execution timed out |
2087 ms |
1408 KB |
Time limit exceeded |
6 |
Execution timed out |
2077 ms |
2432 KB |
Time limit exceeded |
7 |
Execution timed out |
2081 ms |
2176 KB |
Time limit exceeded |
8 |
Execution timed out |
2086 ms |
3584 KB |
Time limit exceeded |
9 |
Execution timed out |
2075 ms |
4736 KB |
Time limit exceeded |
10 |
Execution timed out |
2085 ms |
5376 KB |
Time limit exceeded |