結果

問題 No.533 Mysterious Stairs
ユーザー tottoripapertottoripaper
提出日時 2017-08-04 21:19:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 889 bytes
コンパイル時間 1,375 ms
コンパイル使用メモリ 164,172 KB
実行使用メモリ 26,752 KB
最終ジャッジ日時 2024-04-20 02:05:52
合計ジャッジ時間 2,204 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 7 ms
6,944 KB
testcase_21 AC 6 ms
6,944 KB
testcase_22 AC 16 ms
12,288 KB
testcase_23 AC 40 ms
26,624 KB
testcase_24 AC 42 ms
26,752 KB
testcase_25 AC 6 ms
6,940 KB
testcase_26 AC 36 ms
23,552 KB
testcase_27 AC 11 ms
9,600 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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){
      |                 ~^~~

ソースコード

diff #

#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;
}
0