Submission #494090

# Submission time Handle Problem Language Result Execution time Memory
494090 2021-12-14T09:59:06 Z Jeff12345121 Fishing Game (RMI19_fishing) C++14
0 / 100
2000 ms 524292 KB
#include <bits/stdc++.h>
#define sz(z) ( (int)z.size() )
#define in cin
#define out cout
using namespace std;



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[j] , v[(int)v.size() - 1]);
                v.pop_back();

                swap(v[i] , v[(int)v.size() - 1]);
                v.pop_back();

                eliminated = true;
            }
        }
    }
    return eliminated;
}

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


    if (sol == 0) eliminated = 0;

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

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


int main() {
    int t;

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

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

    }

    return 0;
}

Compilation message

fishing.cpp: In function 'void back(int, std::vector<std::vector<int> >, bool)':
fishing.cpp:48:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for (int i = 0; i < v[l].size(); i++) {
      |                         ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1097 ms 524292 KB Execution killed with signal 9
2 Runtime error 483 ms 524292 KB Execution killed with signal 9
3 Runtime error 1063 ms 524292 KB Execution killed with signal 9
4 Runtime error 486 ms 524292 KB Execution killed with signal 9
5 Execution timed out 2095 ms 444 KB Time limit exceeded
6 Execution timed out 2090 ms 580 KB Time limit exceeded
7 Execution timed out 2072 ms 1184 KB Time limit exceeded
8 Execution timed out 2096 ms 668 KB Time limit exceeded
9 Execution timed out 2085 ms 844 KB Time limit exceeded
10 Execution timed out 2073 ms 964 KB Time limit exceeded