結果
問題 | No.612 Move on grid |
ユーザー |
![]() |
提出日時 | 2017-12-17 18:28:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,549 bytes |
コンパイル時間 | 797 ms |
コンパイル使用メモリ | 85,436 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-18 00:55:19 |
合計ジャッジ時間 | 2,016 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:50:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 50 | scanf("%d%d%d%d%d%d", &t, &a, &b, &c, &d, &e); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 612.cc: No.612 Move on grid - yukicoder */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_T = 500; const int MAX_A = 20; const int MAX_X = MAX_T * MAX_A * 2 + 1; typedef long long ll; const ll MOD = 1000000007; /* typedef */ /* global variables */ ll dp[2][MAX_X]; /* subroutines */ inline void addmod(ll &a, ll b) { a = (a + b) % MOD; } /* main */ int main() { int t, a, b, c, d, e; scanf("%d%d%d%d%d%d", &t, &a, &b, &c, &d, &e); a = abs(a), b = abs(b), c = abs(c); int ox = max(max(a, b), c) * t; int maxx = ox * 2 + 1; dp[0][ox] = 1; int cur = 0, nxt = 1; for (int i = 0; i < t; i++) { memset(dp[nxt], 0, sizeof(dp[nxt])); for (int x = 0; x < maxx; x++) if (dp[cur][x] > 0) { if (x - a >= 0) addmod(dp[nxt][x - a], dp[cur][x]); if (x + a < maxx) addmod(dp[nxt][x + a], dp[cur][x]); if (x - b >= 0) addmod(dp[nxt][x - b], dp[cur][x]); if (x + b < maxx) addmod(dp[nxt][x + b], dp[cur][x]); if (x - c >= 0) addmod(dp[nxt][x - c], dp[cur][x]); if (x + c < maxx) addmod(dp[nxt][x + c], dp[cur][x]); } cur ^= 1, nxt ^= 1; } ll sum = 0; for (int x = d + ox; x <= e + ox; x++) addmod(sum, dp[cur][x]); printf("%lld\n", sum); return 0; }