結果

問題 No.2419 MMA文字列2
ユーザー siro53siro53
提出日時 2023-08-12 15:22:40
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 559 bytes
コンパイル時間 2,540 ms
コンパイル使用メモリ 206,120 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-20 01:39:05
合計ジャッジ時間 5,261 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

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