結果

問題 No.2419 MMA文字列2
ユーザー dmasuprodmasupro
提出日時 2023-08-14 21:22:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,029 bytes
コンパイル時間 963 ms
コンパイル使用メモリ 99,320 KB
実行使用メモリ 223,924 KB
最終ジャッジ日時 2024-05-02 09:26:50
合計ジャッジ時間 7,809 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 29 ms
11,008 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 10 ms
7,936 KB
testcase_27 AC 66 ms
42,584 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main() {
    std::string S;
    std::cin >> S;
    
    std::unordered_set<char> alpha_set(S.begin(), S.end());
    
    // ruiseki[i][s]をS[:i]のアルファベットsの出現回数とする
    std::vector<std::unordered_map<char, int>> ruiseki(S.length() + 1);
    
    for (int i = 0; i < S.length(); ++i) {
        char A = S[i];
        int idx = i + 1;
        
        for (char MM : alpha_set) {
            ruiseki[idx][MM] = ruiseki[idx - 1][MM];
        }
        ruiseki[idx][A] += 1;
    }
    
    int ans = 0;
    for (int i = 0; i < S.length(); ++i) {
        char A = S[i];
        
        for (const auto& entry : ruiseki[i]) {
            char MM = entry.first;
            
            if (A == MM) {
                continue;
            }
            
            ans += ruiseki[i][MM] * (ruiseki[i][MM] - 1) / 2;
        }
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}
0