結果

問題 No.2419 MMA文字列2
ユーザー yansi819yansi819
提出日時 2024-04-07 11:40:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 832 bytes
コンパイル時間 4,490 ms
コンパイル使用メモリ 269,696 KB
実行使用メモリ 13,352 KB
最終ジャッジ日時 2024-04-07 11:40:27
合計ジャッジ時間 13,072 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,352 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 1 ms
6,548 KB
testcase_05 AC 1 ms
6,548 KB
testcase_06 AC 1 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 1 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 776 ms
6,548 KB
testcase_13 AC 21 ms
6,548 KB
testcase_14 TLE -
testcase_15 AC 1,057 ms
6,548 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int main() {
  string S; cin >> S;
  map<char, vector<int>> mp;
  for (int i = 0; i < S.size(); i++) {
    mp[S[i]].push_back(i);
  }
  ll ans = 0;
  for (int i = 0; i < S.size(); i++) {
    if (mp[S[i]].size() >= 2) {
      int pos1 = lower_bound(mp[S[i]].begin(), mp[S[i]].end(), i) - mp[S[i]].begin();
      if (pos1 < mp[S[i]].size() - 1) {
        for (int j = pos1 + 1; j < mp[S[i]].size(); j++) {
          int siz = max(0, (int)mp[S[i]].size() - j - 1);
          ans += S.size() - mp[S[i]][j] - 1 - siz;
          //cout << S[i] << ' ' << S.size() - mp[S[i]][pos1 + 1] - 1 - siz << endl;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
0