結果

問題 No.1885 Flat Permutation
ユーザー tentententen
提出日時 2023-01-17 19:11:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 2,299 bytes
コンパイル時間 2,876 ms
コンパイル使用メモリ 86,084 KB
実行使用メモリ 51,652 KB
最終ジャッジ日時 2023-08-30 22:29:52
合計ジャッジ時間 8,225 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,424 KB
testcase_01 AC 44 ms
49,516 KB
testcase_02 AC 44 ms
49,580 KB
testcase_03 AC 45 ms
49,524 KB
testcase_04 AC 43 ms
49,460 KB
testcase_05 AC 43 ms
49,604 KB
testcase_06 AC 43 ms
49,436 KB
testcase_07 AC 43 ms
49,476 KB
testcase_08 AC 44 ms
49,432 KB
testcase_09 AC 43 ms
49,520 KB
testcase_10 AC 43 ms
49,428 KB
testcase_11 AC 43 ms
49,580 KB
testcase_12 AC 42 ms
49,556 KB
testcase_13 AC 43 ms
49,464 KB
testcase_14 AC 44 ms
49,412 KB
testcase_15 AC 43 ms
49,596 KB
testcase_16 AC 43 ms
49,544 KB
testcase_17 AC 42 ms
49,428 KB
testcase_18 AC 42 ms
49,672 KB
testcase_19 AC 50 ms
49,528 KB
testcase_20 AC 50 ms
49,632 KB
testcase_21 AC 50 ms
49,604 KB
testcase_22 AC 50 ms
49,480 KB
testcase_23 AC 43 ms
49,552 KB
testcase_24 AC 42 ms
49,612 KB
testcase_25 AC 43 ms
49,604 KB
testcase_26 AC 43 ms
49,436 KB
testcase_27 AC 51 ms
49,748 KB
testcase_28 AC 53 ms
49,528 KB
testcase_29 AC 51 ms
51,652 KB
testcase_30 AC 50 ms
49,460 KB
testcase_31 AC 50 ms
49,784 KB
testcase_32 AC 43 ms
49,444 KB
testcase_33 AC 43 ms
49,380 KB
testcase_34 AC 42 ms
49,572 KB
testcase_35 AC 50 ms
49,472 KB
testcase_36 AC 52 ms
49,668 KB
testcase_37 AC 43 ms
49,744 KB
testcase_38 AC 42 ms
49,496 KB
testcase_39 AC 42 ms
49,476 KB
testcase_40 AC 44 ms
49,924 KB
testcase_41 AC 45 ms
49,936 KB
testcase_42 AC 43 ms
47,544 KB
testcase_43 AC 50 ms
49,676 KB
testcase_44 AC 50 ms
49,384 KB
testcase_45 AC 50 ms
49,368 KB
testcase_46 AC 49 ms
49,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int min = Math.min(x, y);
        int max = Math.max(x, y);
        int start;
        if (min == 1) {
            start = 1;
        } else {
            start = min + 1;
        }
        int goal;
        if (max == n) {
            goal = n;
        } else {
            goal = max - 1;
        }
        if (goal < start) {
            System.out.println(0);
            return;
        }
        if (goal - start < 3) {
            System.out.println(1);
            return;
        }
        int[] dp = new int[goal - start + 1];
        dp[0] = 1;
        dp[1] = 1;
        dp[2] = 1;
        for (int i = 3; i < dp.length; i++) {
            dp[i] = (dp[i - 1] + dp[i - 3]) % MOD;
        }
        System.out.println(dp[dp.length - 1]);
    }
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0