結果

問題 No.2419 MMA文字列2
ユーザー siro53siro53
提出日時 2023-08-12 15:22:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 559 bytes
コンパイル時間 2,397 ms
コンパイル使用メモリ 204,536 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-30 09:03:41
合計ジャッジ時間 5,272 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 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,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 47 ms
6,944 KB
testcase_13 AC 8 ms
6,944 KB
testcase_14 AC 96 ms
6,940 KB
testcase_15 AC 58 ms
6,940 KB
testcase_16 AC 101 ms
6,944 KB
testcase_17 AC 30 ms
6,940 KB
testcase_18 AC 108 ms
6,944 KB
testcase_19 AC 111 ms
6,940 KB
testcase_20 AC 33 ms
6,944 KB
testcase_21 AC 22 ms
6,940 KB
testcase_22 AC 32 ms
6,940 KB
testcase_23 AC 32 ms
6,944 KB
testcase_24 AC 22 ms
6,940 KB
testcase_25 AC 22 ms
6,940 KB
testcase_26 AC 4 ms
6,944 KB
testcase_27 AC 14 ms
6,940 KB
testcase_28 AC 242 ms
6,940 KB
testcase_29 AC 243 ms
6,940 KB
testcase_30 AC 239 ms
6,940 KB
testcase_31 AC 240 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  string s;
  cin >> s;
  vector<vector<int>> v(26);
  for(int i = 0; i < s.size(); i++) {
    v[s[i] - 'A'].push_back(i);
  }
  ll ans = 0;
  for(int c = 0; c < 26; c++) {
    if(v[c].size() <= 1) continue;
    for(int i = 1; i < v[c].size(); i++) {
      for(int d = 0; d < 26; d++) {
        if(v[d].empty() or c == d) continue;
        int x = v[d].end() - upper_bound(v[d].begin(), v[d].end(), v[c][i]);
        ans += (ll)i * x;
      }
    }
  }
  cout << ans << endl;
}
0