結果

問題 No.2055 12x34...
ユーザー tentententen
提出日時 2022-08-22 13:06:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 426 ms / 2,000 ms
コード長 1,420 bytes
コンパイル時間 2,423 ms
コンパイル使用メモリ 78,856 KB
実行使用メモリ 62,276 KB
最終ジャッジ日時 2024-04-18 13:23:12
合計ジャッジ時間 16,149 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
36,912 KB
testcase_01 AC 53 ms
36,896 KB
testcase_02 AC 161 ms
42,892 KB
testcase_03 AC 227 ms
45,180 KB
testcase_04 AC 247 ms
44,876 KB
testcase_05 AC 243 ms
45,092 KB
testcase_06 AC 240 ms
45,092 KB
testcase_07 AC 239 ms
45,064 KB
testcase_08 AC 195 ms
44,704 KB
testcase_09 AC 241 ms
45,264 KB
testcase_10 AC 251 ms
44,904 KB
testcase_11 AC 188 ms
44,408 KB
testcase_12 AC 323 ms
52,420 KB
testcase_13 AC 393 ms
56,152 KB
testcase_14 AC 262 ms
49,064 KB
testcase_15 AC 254 ms
49,136 KB
testcase_16 AC 388 ms
56,528 KB
testcase_17 AC 276 ms
47,712 KB
testcase_18 AC 315 ms
51,336 KB
testcase_19 AC 187 ms
44,644 KB
testcase_20 AC 138 ms
41,804 KB
testcase_21 AC 197 ms
44,364 KB
testcase_22 AC 383 ms
55,224 KB
testcase_23 AC 359 ms
56,320 KB
testcase_24 AC 381 ms
61,948 KB
testcase_25 AC 359 ms
57,104 KB
testcase_26 AC 374 ms
58,316 KB
testcase_27 AC 426 ms
62,276 KB
testcase_28 AC 385 ms
61,092 KB
testcase_29 AC 361 ms
60,520 KB
testcase_30 AC 372 ms
60,640 KB
testcase_31 AC 384 ms
59,380 KB
testcase_32 AC 392 ms
60,556 KB
testcase_33 AC 298 ms
45,632 KB
testcase_34 AC 309 ms
45,824 KB
testcase_35 AC 317 ms
45,768 KB
testcase_36 AC 299 ms
45,420 KB
testcase_37 AC 319 ms
45,444 KB
testcase_38 AC 319 ms
45,712 KB
testcase_39 AC 307 ms
45,460 KB
testcase_40 AC 296 ms
45,380 KB
testcase_41 AC 302 ms
45,392 KB
testcase_42 AC 306 ms
45,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        HashMap<Integer, Integer> counts = new HashMap<>();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            if (counts.containsKey(x - 1)) {
                ans += counts.get(x - 1);
                ans %= MOD;
                counts.put(x, (counts.getOrDefault(x, 0) + counts.get(x - 1) + 1) % MOD);
            } else {
                counts.put(x, counts.getOrDefault(x, 0) + 1);
            }
        }
        System.out.println(ans);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0