結果

問題 No.612 Move on grid
ユーザー pekempey
提出日時 2017-12-12 00:05:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 150 ms / 2,500 ms
コード長 776 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 70,852 KB
実行使用メモリ 87,424 KB
最終ジャッジ日時 2024-12-18 00:44:51
合計ジャッジ時間 3,411 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

// 20 * 500 * 2

const long long mod = 1e9 + 7;

long long dp[501][22020];

void to(long long &x, long long y) {
  x += y;
  if (x >= mod) x -= mod;
}

int main() {
  int n;
  cin >> n;

  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;

  dp[0][10200] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = 50; j < 21000; j++) {
      to(dp[i + 1][j + a], dp[i][j]);
      to(dp[i + 1][j - a], dp[i][j]);
      to(dp[i + 1][j + b], dp[i][j]);
      to(dp[i + 1][j - b], dp[i][j]);
      to(dp[i + 1][j + c], dp[i][j]);
      to(dp[i + 1][j - c], dp[i][j]);
    }
  }

  long long ans = 0;
  for (int i = 10200 + d; i <= 10200 + e; i++) {
    to(ans, dp[n][i]);
  }
  cout << ans << endl;
}
0