結果

問題 No.612 Move on grid
コンテスト
ユーザー yuppe19 😺
提出日時 2017-12-12 19:25:21
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 779 ms / 2,500 ms
コード長 756 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,314 ms
コンパイル使用メモリ 177,332 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-08 16:15:23
合計ジャッジ時間 8,091 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |   int T; scanf("%d", &T);
      |          ~~~~~^~~~~~~~~~
main.cpp:9:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |   int a, b, c, d, e; scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;

int main(void) {
  constexpr int mod = int(powl(10, 9)) + 7;
  int T; scanf("%d", &T);
  int a, b, c, d, e; scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
  unordered_map<int, int> dp, ndp;
  dp[0] = 1;
  for(int t=0; t<T; ++t) {
    ndp.clear();
    for(auto&& kv : dp) {
      int cur = kv.first;
      (ndp[cur + a] += dp[cur]) %= mod;
      (ndp[cur - a] += dp[cur]) %= mod;
      (ndp[cur + b] += dp[cur]) %= mod;
      (ndp[cur - b] += dp[cur]) %= mod;
      (ndp[cur + c] += dp[cur]) %= mod;
      (ndp[cur - c] += dp[cur]) %= mod;
    }
    dp = ndp;
  }
  int res = 0;
  for(int r=d; r<=e; ++r) {
    (res += dp[r]) %= mod;
  }
  printf("%d\n", res);
  return 0;
}
0