結果

問題 No.533 Mysterious Stairs
ユーザー rodea
提出日時 2019-03-26 18:19:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 1,195 bytes
コンパイル時間 952 ms
コンパイル使用メモリ 101,208 KB
実行使用メモリ 34,708 KB
最終ジャッジ日時 2024-10-11 01:34:17
合計ジャッジ時間 1,833 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

ll dp[1000010][4];

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

    dp[0][1] = 1;
    dp[1][1] = 1;
    dp[2][2] = 1;
    for(int i=2; i<n; i++){
        dp[i+1][1] = (dp[i][2] + dp[i][3]) % MOD;
        dp[i+1][2] = (dp[i-1][3] + dp[i-1][1]) % MOD;
        dp[i+1][3] = (dp[i-2][1] + dp[i-2][2]) % MOD;
    }

    cout << (dp[n][1] + dp[n][2] + dp[n][3]) % MOD << endl;
}
0