結果

問題 No.1171 Runs in Subsequences
ユーザー tentententen
提出日時 2021-01-22 12:42:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,356 bytes
コンパイル時間 3,487 ms
コンパイル使用メモリ 81,428 KB
実行使用メモリ 98,568 KB
最終ジャッジ日時 2023-08-27 03:03:31
合計ジャッジ時間 12,058 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
56,148 KB
testcase_01 AC 116 ms
55,632 KB
testcase_02 AC 121 ms
55,792 KB
testcase_03 AC 120 ms
55,608 KB
testcase_04 AC 119 ms
55,424 KB
testcase_05 AC 116 ms
55,304 KB
testcase_06 AC 119 ms
55,876 KB
testcase_07 AC 117 ms
56,096 KB
testcase_08 AC 115 ms
55,664 KB
testcase_09 AC 115 ms
55,556 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        ArrayList<HashMap<Integer, Integer>> counts = new ArrayList<>();
        HashMap<Integer, Integer> total = new HashMap<>();
        for (int i = 0; i < 26; i++) {
            counts.add(new HashMap<>());
        }
        for (char c : sc.next().toCharArray()) {
            int idx = c - 'a';
            for (int x : counts.get(idx).keySet()) {
                total.put(x, (total.get(x) - counts.get(idx).get(x) + MOD) % MOD);
                counts.get(idx).put(x, counts.get(idx).get(x) * 2 % MOD);
            }
            counts.get(idx).put(1, counts.get(idx).getOrDefault(1, 0) + 1);
            for (int x : total.keySet()) {
                counts.get(idx).put(x + 1, (counts.get(idx).getOrDefault(x + 1, 0) + total.get(x)) % MOD);
            }
            for (int x : counts.get(idx).keySet()) {
                total.put(x, total.getOrDefault(x, 0) + counts.get(idx).get(x));
            }
        }
        long ans = 0;
        for (Map.Entry<Integer, Integer> entry : total.entrySet()) {
            ans += (long)(entry.getKey().intValue()) * entry.getValue() % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
0