結果

問題 No.533 Mysterious Stairs
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2017-06-23 22:51:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 334 ms / 5,000 ms
コード長 774 bytes
コンパイル時間 1,889 ms
コンパイル使用メモリ 77,404 KB
実行使用メモリ 102,268 KB
最終ジャッジ日時 2024-04-15 00:58:38
合計ジャッジ時間 10,750 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 268 ms
101,648 KB
testcase_01 AC 271 ms
102,060 KB
testcase_02 AC 270 ms
101,644 KB
testcase_03 AC 267 ms
100,972 KB
testcase_04 AC 270 ms
102,064 KB
testcase_05 AC 266 ms
102,048 KB
testcase_06 AC 265 ms
100,944 KB
testcase_07 AC 267 ms
101,728 KB
testcase_08 AC 268 ms
101,604 KB
testcase_09 AC 265 ms
101,964 KB
testcase_10 AC 262 ms
101,904 KB
testcase_11 AC 270 ms
101,776 KB
testcase_12 AC 249 ms
101,784 KB
testcase_13 AC 267 ms
101,708 KB
testcase_14 AC 272 ms
101,876 KB
testcase_15 AC 271 ms
102,068 KB
testcase_16 AC 270 ms
100,984 KB
testcase_17 AC 269 ms
101,884 KB
testcase_18 AC 273 ms
101,880 KB
testcase_19 AC 294 ms
102,144 KB
testcase_20 AC 293 ms
101,780 KB
testcase_21 AC 292 ms
101,784 KB
testcase_22 AC 290 ms
102,112 KB
testcase_23 AC 334 ms
101,928 KB
testcase_24 AC 334 ms
102,268 KB
testcase_25 AC 292 ms
102,132 KB
testcase_26 AC 312 ms
101,792 KB
testcase_27 AC 288 ms
102,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long mod = (long)Math.pow(10,9)+7;
        long [][] num = new long [1000001][4];
        num[1][1] = 1;
        num[2][2] = 1;
        num[3][1] = 1;
        num[3][2] = 1;
        num[3][3] = 1;
        for(int i=4; i<=N; i++){
            num[i][1] = num[i-1][2]+num[i-1][3];
            num[i][2] = num[i-2][1]+num[i-2][3];
            num[i][3] = num[i-3][1]+num[i-3][2];
            for(int j=0; j<3; j++){
                num[i][j]%=mod;
            }
        }
        long ans=0;
        for(int i=1; i<=3; i++){
            ans+=num[N][i];
        }
        System.out.println(ans%mod);
    }
}
0