답안 #332233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332233 2020-12-01T18:13:19 Z AlexPop28 Fishing Game (RMI19_fishing) C++11
0 / 100
253 ms 191164 KB
#include <bits/stdc++.h>
#define dbg() cerr <<
#define name(x) (#x) << ": " << (x) << ' ' <<

using namespace std;

void Read(vector<int> &v) {
  for (int &x : v) cin >> x; 
}

int CountPairs(const vector<int> &a, const vector<int> &b) {
  int ans = 0; for (auto &x : a) for (auto &y : b) ans += x == y; return ans;
}

const int MOD = (int)1e9 + 7;
const int N = 100;

int Add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  if (a < 0) a += MOD;
  return a;
}

int Mul(int a, int b) {
  return 1LL * a * b % MOD;
}

int dp[2 * N + 1][2 * N + 1][2 * N + 1][3][2];

int DP(int ab, int bc, int ca, int pos, bool discarded) {
  int &curr = dp[ab][bc][ca][pos][discarded];
  if (curr != -1) return curr;
  if (ab == 0 && bc == 0 && ca == 0) return 1;

  curr = 0;

  auto Upd = [&](int val) {
    curr = Add(curr, val);
  };

  if (pos == 0) {
    if (ab > 0) {
      Upd(Mul(ab, DP(ab - 1, bc, ca, 1, true))); 
    }
    if (ca > 0) {
      Upd(Mul(ca, DP(ab, 1 + bc, ca - 1, 1, false)));
    }
  }

  if (pos == 1) {
    if (bc > 0) {
      Upd(Mul(bc, DP(ab, bc - 1, ca, 2, true)));
    }
    if (ab > 0) {
      Upd(Mul(ab, DP(ab - 1, bc, 1 + ca, 2, discarded)));
    }
  }

  if (pos == 2) {
    if (ca > 0) {
      Upd(Mul(ca, DP(ab, bc, ca - 1, 0, false)));
    }
    if (bc > 0 && discarded) {
      Upd(Mul(bc, DP(1 + ab, bc - 1, ca, 0, false)));
    }
  }

  // dbg() name(ab) name(bc) name(ca) name(pos) name(discarded) name(curr) endl;
  return curr;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  memset(dp, -1, sizeof(dp));

  int n, t; cin >> n >> t;
  while (t--) {
    vector<int> a(2 * n), b(2 * n), c(2 * n);
    Read(a); Read(b); Read(c);

    int ab = CountPairs(a, b);
    int bc = CountPairs(b, c);
    int ca = CountPairs(c, a);

//    dbg() name(ab) name(bc) name(ca) endl;
    cout << DP(ab, bc, ca, 0, false) << '\n';
  }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 101 ms 191084 KB Output isn't correct
2 Incorrect 98 ms 191084 KB Output isn't correct
3 Incorrect 104 ms 191084 KB Output isn't correct
4 Incorrect 103 ms 191084 KB Output isn't correct
5 Incorrect 130 ms 191052 KB Output isn't correct
6 Incorrect 134 ms 191164 KB Output isn't correct
7 Incorrect 151 ms 191048 KB Output isn't correct
8 Incorrect 184 ms 191084 KB Output isn't correct
9 Incorrect 221 ms 191128 KB Output isn't correct
10 Incorrect 253 ms 191084 KB Output isn't correct