結果

問題 No.1171 Runs in Subsequences
ユーザー tentententen
提出日時 2021-01-22 11:52:00
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,310 bytes
コンパイル時間 2,323 ms
コンパイル使用メモリ 76,804 KB
実行使用メモリ 77,748 KB
最終ジャッジ日時 2023-08-27 02:09:38
合計ジャッジ時間 13,159 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,564 KB
testcase_01 AC 120 ms
55,612 KB
testcase_02 AC 123 ms
55,364 KB
testcase_03 AC 150 ms
55,388 KB
testcase_04 AC 125 ms
57,048 KB
testcase_05 AC 125 ms
55,408 KB
testcase_06 AC 124 ms
55,820 KB
testcase_07 AC 125 ms
55,408 KB
testcase_08 AC 125 ms
55,628 KB
testcase_09 AC 119 ms
55,428 KB
testcase_10 AC 1,097 ms
68,992 KB
testcase_11 AC 1,081 ms
69,136 KB
testcase_12 AC 1,110 ms
69,300 KB
testcase_13 AC 1,070 ms
70,320 KB
testcase_14 AC 1,064 ms
68,620 KB
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<>();
        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()) {
                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 i = 0; i < 26; i++) {
                if (idx == i) {
                    continue;
                }
                for (int x : counts.get(i).keySet()) {
                    counts.get(idx).put(x + 1, (counts.get(idx).getOrDefault(x + 1, 0) + counts.get(i).get(x)) % MOD);
                }
            }
        }
        long ans = 0;
        for (HashMap<Integer, Integer> map : counts) {
            for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
                ans += (long)(entry.getKey().intValue()) * entry.getValue() % MOD;
                ans %= MOD;
            }
        }
        System.out.println(ans);
    }
}
0