結果

問題 No.2419 MMA文字列2
ユーザー ochiaigawaochiaigawa
提出日時 2023-08-12 14:07:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 1,834 ms
コンパイル使用メモリ 204,732 KB
実行使用メモリ 30,004 KB
最終ジャッジ日時 2024-04-30 05:02:02
合計ジャッジ時間 3,188 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 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 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 10 ms
9,216 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 18 ms
14,720 KB
testcase_15 AC 10 ms
10,368 KB
testcase_16 AC 18 ms
15,232 KB
testcase_17 AC 7 ms
6,944 KB
testcase_18 AC 20 ms
15,872 KB
testcase_19 AC 18 ms
16,176 KB
testcase_20 AC 7 ms
7,168 KB
testcase_21 AC 5 ms
6,944 KB
testcase_22 AC 38 ms
29,952 KB
testcase_23 AC 38 ms
29,940 KB
testcase_24 AC 37 ms
29,992 KB
testcase_25 AC 36 ms
29,816 KB
testcase_26 AC 7 ms
6,944 KB
testcase_27 AC 37 ms
29,940 KB
testcase_28 AC 39 ms
30,004 KB
testcase_29 AC 38 ms
30,004 KB
testcase_30 AC 38 ms
29,856 KB
testcase_31 AC 40 ms
29,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0); cout.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.length();
  vector<vector<int>> C(N + 1, vector<int>(26, 0));
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 26; j++) {
      C[i + 1][j] += C[i][j];
    }
    C[i + 1][S[i] - 'A']++;
  }
  long long ans = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 26; j++) {
      if(S[i] - 'A' != j) {
        ans += (long long) C[i][j] * (C[i][j] - 1) / 2;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
0