結果

問題 No.612 Move on grid
ユーザー kk
提出日時 2021-04-02 21:43:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 261 ms / 2,500 ms
コード長 1,519 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 199,432 KB
実行使用メモリ 101,420 KB
最終ジャッジ日時 2023-08-25 11:53:23
合計ジャッジ時間 6,598 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 5 ms
4,824 KB
testcase_03 AC 55 ms
27,000 KB
testcase_04 AC 220 ms
101,264 KB
testcase_05 AC 253 ms
101,280 KB
testcase_06 AC 261 ms
101,260 KB
testcase_07 AC 233 ms
101,420 KB
testcase_08 AC 259 ms
101,240 KB
testcase_09 AC 241 ms
101,224 KB
testcase_10 AC 153 ms
64,572 KB
testcase_11 AC 70 ms
32,476 KB
testcase_12 AC 182 ms
76,432 KB
testcase_13 AC 100 ms
44,444 KB
testcase_14 AC 223 ms
88,200 KB
testcase_15 AC 74 ms
34,264 KB
testcase_16 AC 237 ms
100,116 KB
testcase_17 AC 101 ms
46,348 KB
testcase_18 AC 220 ms
89,952 KB
testcase_19 AC 161 ms
70,452 KB
testcase_20 AC 218 ms
95,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;
const int ZERO = 25000;
int dp[501][50000];
long long f[501], g[501];

long long modpow(long long x, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    p >>= 1;
  }
  return ret;
}

long long comb(int n, int k) {
  return f[n] * g[n-k] % MOD * g[k] % MOD;
}

void init() {
  f[0] = g[0] = 1;
  for (int i = 1; i <= 500; i++) {
    f[i] = f[i-1] * i % MOD;
    g[i] = modpow(f[i], MOD-2, MOD);
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  init();
  
  int T, a, b, c, d, e;
  cin >> T >> a >> b >> c >> d >> e;

  dp[0][ZERO] = 1;
  for (int t = 0; t < T; t++) {
    for (int i = 0; i < 50000; i++) {
      if (dp[t][i]) {
        (dp[t+1][i-b] += dp[t][i]) %= MOD;
        (dp[t+1][i+b] += dp[t][i]) %= MOD;
        (dp[t+1][i-c] += dp[t][i]) %= MOD;
        (dp[t+1][i+c] += dp[t][i]) %= MOD;
      }
    }
  }

  for (int t = 0; t <= T; t++) {
    for (int i = 1; i < 50000; i++)
      dp[t][i] = (dp[t][i] + dp[t][i-1]) % MOD;
  }

  long long ret = 0;
  for (int l = 0; l <= T; l++) {
    for (int r = 0; l + r <= T; r++) {
      int x = r - l;
      long long tmp = dp[T - l - r][ZERO + e - a * x] - dp[T - l - r][ZERO + d - a * x - 1];
      if (tmp < 0)
        tmp += MOD;
      tmp = tmp * comb(T, l) % MOD;
      tmp = tmp * comb(T-l, r) % MOD;
      ret += tmp;
      ret %= MOD;
    }
  }

  cout << ret << endl;
  
  return 0;
}
0