結果
問題 | No.533 Mysterious Stairs |
ユーザー |
![]() |
提出日時 | 2017-09-06 19:30:38 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 23 ms / 5,000 ms |
コード長 | 1,147 bytes |
コンパイル時間 | 911 ms |
コンパイル使用メモリ | 88,584 KB |
実行使用メモリ | 26,880 KB |
最終ジャッジ日時 | 2024-11-06 23:55:55 |
合計ジャッジ時間 | 2,096 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:51:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 51 | scanf("%d",&n); | ~~~~~^~~~~~~~~
ソースコード
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <complex> #include <functional> #include <cassert> typedef long long ll; using namespace std; #define debug(x) cerr << #x << " = " << (x) << endl; #define mod 1000000007 //1e9+7(prime number) #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define SIZE 1000100 ll power(int k,int n,int M){ if(n==0) return 1; if(n==1) return (ll)k; ll ret = power(k,n/2,M); ret=(ret*ret)%M; if(n%2==1) ret=(ret*k)%M; return ret; } ll dp[3][SIZE]; int main(){ int n; scanf("%d",&n); dp[0][0] = dp[1][0] = dp[2][0] = 1; for(int i=1;i<=n;i++){ if(i >= 1) dp[0][i] = (dp[1][i-1] + dp[2][i-1])%mod; if(i >= 2) dp[1][i] = (dp[0][i-2] + dp[2][i-2])%mod; if(i >= 3) dp[2][i] = (dp[0][i-3] + dp[1][i-3])%mod; } printf("%lld\n",(dp[0][n] + dp[1][n] + dp[2][n])%mod * power(2, mod-2, mod) % mod); return 0; }