結果

問題 No.2419 MMA文字列2
ユーザー ochiaigawaochiaigawa
提出日時 2023-08-12 14:07:02
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 2,527 ms
コンパイル使用メモリ 204,264 KB
実行使用メモリ 29,952 KB
最終ジャッジ日時 2024-11-19 17:25:44
合計ジャッジ時間 3,714 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

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