結果
問題 | No.2419 MMA文字列2 |
ユーザー | dyktr_06 |
提出日時 | 2023-07-26 12:57:44 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 66 ms / 2,000 ms |
コード長 | 619 bytes |
コンパイル時間 | 1,899 ms |
コンパイル使用メモリ | 205,032 KB |
実行使用メモリ | 51,840 KB |
最終ジャッジ日時 | 2024-10-02 22:44:16 |
合計ジャッジ時間 | 3,864 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int n = s.size(); long long ans = 0; vector<vector<long long>> sum(n + 1, vector<long long>(26)); for(int i = 0; i < n; i++){ for(int j = 0; j < 26; j++){ sum[i + 1][j] += sum[i][j]; } sum[i + 1][s[i] - 'A']++; } for(int i = n - 1; i >= 0; i--){ for(int j = 0; j < 26; j++){ if(s[i] - 'A' == j) continue; ans += sum[i][j] * (sum[i][j] - 1) / 2; } } cout << ans << "\n"; }