結果
問題 | No.2419 MMA文字列2 |
ユーザー |
|
提出日時 | 2023-07-12 15:48:05 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 878 bytes |
コンパイル時間 | 1,494 ms |
コンパイル使用メモリ | 121,344 KB |
実行使用メモリ | 75,648 KB |
最終ジャッジ日時 | 2024-09-14 05:28:08 |
合計ジャッジ時間 | 3,327 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
#include <iostream>#include <cassert>#include <string>#include <vector>using namespace std;using ll = long long;void assert_str(string& s) {assert(3 <= s.length() && s.length() <= 200000);for (auto c : s) {assert('A' <= c && c <= 'Z');}}int main() {string s;cin >> s;assert_str(s);int n = s.length();vector cnt_sum('Z' + 1, vector<int>(n + 1));for (int i = 0; i < n; ++i) {cnt_sum[s[i]][i + 1] += 1;for (char c = 'A'; c <= 'Z'; ++c) {cnt_sum[c][i + 1] += cnt_sum[c][i];}}ll ans = 0;for (int i = 0; i < n; ++i) {for (char c = 'A'; c <= 'Z'; ++c) {if (s[i] == c) {continue;}ll cnt = cnt_sum[c][i];ans += cnt * (cnt - 1) / 2;}}cout << ans << endl;return 0;}