# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
443994 | JovanB | Fishing Game (RMI19_fishing) | C++17 | 1959 ms | 117016 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;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;
int add(int a, int b){ a += b; if(a >= MOD) a -= MOD; return a; }
int mul(int a, int b){ return (1LL*a*b)%MOD; }
vector <int> pos[605];
const int G = 205;
int hsh(int a, int b, int c, int turn, int dis){
return G*G*G*a + G*G*b + G*c + 10*turn + dis;
}
map <int, int> dp;
int resi(int a, int b, int c, int turn, int dis){
/// a = 1 i 2
/// b = 2 i 3
/// c = 3 i 1
if(a == 0 && b == 0 && c == 0) return 1;
int k = dp[hsh(a, b, c, turn, dis)];
if(k) return k-1;
if(turn == 1){
if(a > 0) k = add(k, mul(a, resi(a-1, b, c, 2, 1)));
if(c > 0) k = add(k, mul(c, resi(a, b+1, c-1, 2, dis)));
if(a == 0 && c == 0) k = add(k, resi(a, b, c, 2, dis));
}
else if(turn == 2){
if(b > 0) k = add(k, mul(b, resi(a, b-1, c, 3, 1)));
if(a > 0) k = add(k, mul(a, resi(a-1, b, c+1, 3, dis)));
if(a == 0 && b == 0) k = add(k, resi(a, b, c, 3, dis));
}
else{
if(c > 0) k = add(k, mul(c, resi(a, b, c-1, 1, 0)));
if(dis && b > 0) k = add(k, mul(b, resi(a+1, b-1, c, 1, 0)));
if(c == 0 && b == 0 && dis) k = add(k, resi(a, b, c, 1, 0));
}
dp[hsh(a, b, c, turn, dis)] = k+1;
return k;
}
void solve(int n){
for(int i=1; i<=3*n; i++) pos[i].clear();
for(int i=1; i<=2*n; i++){
int x;
cin >> x;
pos[x].push_back(1);
}
for(int i=1; i<=2*n; i++){
int x;
cin >> x;
pos[x].push_back(2);
}
for(int i=1; i<=2*n; i++){
int x;
cin >> x;
pos[x].push_back(3);
}
int ima1 = 0, ima2 = 0, ima3 = 0;
for(int i=1; i<=3*n; i++){
if(pos[i].size() >= 2 && pos[i][0] != pos[i][1]){
if(pos[i][0] == 1){
if(pos[i][1] == 2) ima1++;
else ima3++;
}
else ima2++;
}
}
cout << resi(ima1, ima2, ima3, 1, 0) << "\n";
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, t;
cin >> n >> t;
while(t--) solve(n);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |