답안 #494085

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494085 2021-12-14T09:34:42 Z Jeff12345121 Fishing Game (RMI19_fishing) C++14
0 / 100
2000 ms 552 KB
#include <bits/stdc++.h>
#define sz(z) ( (int)z.size() )
using namespace std;

ifstream in("in.in");
ofstream out("out.out");

const int mod = 1000000007;
int n,sol = 0;

bool discard(vector<int> &v) {
    bool eliminated = false;
    for (int i = 0; i + 1 < sz(v); i++) {
        for (int j = i + 1; j < sz(v); j++) {
            if (v[i] == v[j]) {
                swap(v[i] , v[sz(v) - 1]);
                v.pop_back();

                swap(v[j] , v[sz(v) - 1]);
                v.pop_back();

                eliminated = true;
            }
        }
    }
    return eliminated;
}

void back(int round, vector<int> v[3], bool eliminated) {
    int mround = round % 3;
    if (mround == 0 && eliminated == 0) {
        sol++;
        return;
    } else if (sol == 0) eliminated = 0;

    int l = mround, r = (mround + 1) % 3;

    if (sz(v[l]) == 0) {
        back(round + 1 , v , eliminated);
    } else {
        for (int i = 0; i < sz(v[l]); i++) {
            vector<int> newv[3] = {v[0] , v[1] , v[2]};
            int x = newv[l][i];
            swap(newv[l][i] , newv[l][sz(newv[l]) - 1]);
            newv[l].pop_back();
            newv[r].push_back(x);
            eliminated = discard(newv[r]);
            back(round + 1, newv, eliminated);
        }
    }
  //  cout << "\n";
}


int main() {
    int t;
    cin >> t;
    while (t--) {
        cin >> n;
        vector<int> v[3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 2 * n; j++) {
                int x;
                cin >> x;
                v[i].push_back(x);
            }
        }

        sol = 0;
        for (int i = 0; i < 3; i++) discard(v[i]);
        back(0 , v , 1);
       // cout << "\n";
        cout << sol % mod << "\n";

    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Execution timed out 2081 ms 204 KB Time limit exceeded
3 Execution timed out 2080 ms 204 KB Time limit exceeded
4 Execution timed out 2029 ms 204 KB Time limit exceeded
5 Execution timed out 2094 ms 204 KB Time limit exceeded
6 Execution timed out 2088 ms 288 KB Time limit exceeded
7 Execution timed out 2091 ms 204 KB Time limit exceeded
8 Execution timed out 2075 ms 428 KB Time limit exceeded
9 Execution timed out 2039 ms 332 KB Time limit exceeded
10 Execution timed out 2089 ms 552 KB Time limit exceeded