結果
問題 | No.533 Mysterious Stairs |
ユーザー |
![]() |
提出日時 | 2017-08-04 21:19:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 51 ms / 5,000 ms |
コード長 | 889 bytes |
コンパイル時間 | 1,616 ms |
コンパイル使用メモリ | 165,964 KB |
実行使用メモリ | 26,880 KB |
最終ジャッジ日時 | 2024-10-11 20:57:05 |
合計ジャッジ時間 | 2,697 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:40:29: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations] 40 | res = (res + dp[N][i]) % MOD; | ~~~~~~~^ main.cpp:39:18: note: within this loop 39 | for(int i=1;i<=3;++i){ | ~^~~
ソースコード
#include <bits/stdc++.h>using namespace std;#define fst(t) std::get<0>(t)#define snd(t) std::get<1>(t)#define thd(t) std::get<2>(t)using ll = long long;using P = std::tuple<int,int>;const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};ll dp[1000100][3];const ll MOD = 1e9 + 7;int main(){std::cin.tie(nullptr);std::ios::sync_with_stdio(false);int N;std::cin >> N;dp[1][1] = 1ll;dp[2][2] = 1ll;dp[3][3] = 1ll;for(int i=1;i<N;++i){for(int j=1;j<=3;++j){for(int k=1;k<=3;++k){if(k == j){continue;}if(i + k > N){continue;}dp[i + k][k] = (dp[i + k][k] + dp[i][j]) % MOD;}}}ll res = 0ll;for(int i=1;i<=3;++i){res = (res + dp[N][i]) % MOD;}std::cout << res << std::endl;}