結果

問題 No.1171 Runs in Subsequences
コンテスト
ユーザー tenten
提出日時 2021-01-22 12:42:54
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,356 bytes
コンパイル時間 4,163 ms
コンパイル使用メモリ 79,568 KB
実行使用メモリ 122,152 KB
最終ジャッジ日時 2024-12-26 09:42:37
合計ジャッジ時間 33,417 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 6 WA * 5 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

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