답안 #259547

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259547 2020-08-08T02:15:54 Z cheeheng Fishing Game (RMI19_fishing) C++14
0 / 100
690 ms 524292 KB
#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

fishing.cpp: In function 'int main()':
fishing.cpp:98: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:107:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
fishing.cpp:117:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
fishing.cpp:127:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 379 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 428 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 550 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 566 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 648 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 662 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 662 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 659 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 690 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 674 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)