結果

問題 No.612 Move on grid
ユーザー 0w1
提出日時 2017-12-26 21:04:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 85 ms / 2,500 ms
コード長 980 bytes
コンパイル時間 2,217 ms
コンパイル使用メモリ 198,688 KB
最終ジャッジ日時 2025-01-05 06:32:48
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

const int MOD = 1e9 + 7;

int Dp(int t, int a, int b, int c, int d, int e) {
  int maxabc = std::max({std::abs(a), std::abs(b), std::abs(c)});
  std::vector<std::vector<int>> dp(2, std::vector<int>(2 * t * maxabc + 1));
  dp[0][t * maxabc] = 1;
  int trans[] = {-a, a, -b, b, -c, c};
  for (int i = 0; i < t; ++i) {
    std::fill(dp[~i & 1].begin(), dp[~i & 1].end(), 0);
    for (int j = -i * maxabc; j <= i * maxabc; ++j) {
      for (int k = 0; k < 6; ++k) {
        (dp[~i & 1][t * maxabc + j + trans[k]] += dp[i & 1][t * maxabc + j]) %= MOD;
      }
    }
  }
  int res = 0;
  for (int i = d; i <= e; ++i) {
    if (t * maxabc + i < 0 || 2 * t * maxabc < t * maxabc + i) continue;
    (res += dp[t & 1][t * maxabc + i]) %= MOD;
  }
  return res;
}

signed main() {
  std::ios::sync_with_stdio(false);
  int T;
  std::cin >> T;
  int A, B, C, D, E;
  std::cin >> A >> B >> C >> D >> E;
  std::cout << Dp(T, A, B, C, D, E) << std::endl;
  return 0;
}
0