結果

問題 No.612 Move on grid
ユーザー 0x19f0x19f
提出日時 2017-12-12 00:49:40
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 247 ms / 2,500 ms
コード長 857 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 159,552 KB
実行使用メモリ 120,896 KB
最終ジャッジ日時 2024-12-18 00:45:09
合計ジャッジ時間 5,039 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll T, A, B, C, D, E;
ll dp[501][30000];

int main(void) {
  cin >> T >> A >> B >> C >> D >> E;

  const ll P = 15000;
  REP(i, 0, 501) REP(j, 0, 30000) dp[i][j] = 0;
  dp[0][P] = 1;

  REP(t, 0, T) {
    REP(i, 0, 30000) {
      if(i + A < 30000) (dp[t + 1][i + A] += dp[t][i]) %= MOD;
      if(0 <= i - A)    (dp[t + 1][i - A] += dp[t][i]) %= MOD;
      if(i + B < 30000) (dp[t + 1][i + B] += dp[t][i]) %= MOD;
      if(0 <= i - B)    (dp[t + 1][i - B] += dp[t][i]) %= MOD;
      if(i + C < 30000) (dp[t + 1][i + C] += dp[t][i]) %= MOD;
      if(0 <= i - C)    (dp[t + 1][i - C] += dp[t][i]) %= MOD;
    }
  }

  ll ans = 0;
  REP(i, P + D, P + E + 1) (ans += dp[T][i]) %= MOD;
  cout << ans << endl;
}
0