結果
問題 | No.1885 Flat Permutation |
ユーザー |
![]() |
提出日時 | 2023-01-17 19:11:55 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 2,299 bytes |
コンパイル時間 | 2,780 ms |
コンパイル使用メモリ | 86,544 KB |
実行使用メモリ | 51,352 KB |
最終ジャッジ日時 | 2025-01-02 20:45:04 |
合計ジャッジ時間 | 6,919 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
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(); } }