結果

問題 No.2419 MMA文字列2
ユーザー tnakao0123tnakao0123
提出日時 2023-08-21 15:11:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 42,456 KB
実行使用メモリ 23,480 KB
最終ジャッジ日時 2023-08-21 15:11:29
合計ジャッジ時間 1,753 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,024 KB
testcase_01 AC 2 ms
5,064 KB
testcase_02 AC 2 ms
5,004 KB
testcase_03 AC 2 ms
5,028 KB
testcase_04 AC 2 ms
5,080 KB
testcase_05 AC 2 ms
5,076 KB
testcase_06 AC 2 ms
5,044 KB
testcase_07 AC 2 ms
5,080 KB
testcase_08 AC 2 ms
5,024 KB
testcase_09 AC 1 ms
5,028 KB
testcase_10 AC 2 ms
5,020 KB
testcase_11 AC 2 ms
5,036 KB
testcase_12 AC 5 ms
9,552 KB
testcase_13 AC 2 ms
5,720 KB
testcase_14 AC 6 ms
13,800 KB
testcase_15 AC 6 ms
10,392 KB
testcase_16 AC 7 ms
14,216 KB
testcase_17 AC 4 ms
7,716 KB
testcase_18 AC 8 ms
14,640 KB
testcase_19 AC 8 ms
14,896 KB
testcase_20 AC 5 ms
8,148 KB
testcase_21 AC 4 ms
7,156 KB
testcase_22 AC 11 ms
23,464 KB
testcase_23 AC 10 ms
23,480 KB
testcase_24 AC 11 ms
23,440 KB
testcase_25 AC 10 ms
23,464 KB
testcase_26 AC 4 ms
7,460 KB
testcase_27 AC 10 ms
23,464 KB
testcase_28 AC 10 ms
23,464 KB
testcase_29 AC 10 ms
23,460 KB
testcase_30 AC 10 ms
23,468 KB
testcase_31 AC 10 ms
23,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2419.cc:  No.2419 MMA文字列2 - yukicoder
 */

#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_N + 4];
int qs[26], rs[MAX_N + 1][26];

/* subroutines */

/* main */

int main() {
  scanf("%s", s);
  int n = strlen(s);

  for (int i = n - 1; i >= 0; i--) {
    copy(rs[i + 1], rs[i + 1] + 26, rs[i]);
    rs[i][s[i] - 'A']++;
  }

  ll sum = 0;
  for (int i = 0; i < n; i++) {
    int si = s[i] - 'A';
    sum += (ll)qs[si] * (n - (i + 1) - rs[i + 1][si]);
    qs[si]++;
  }

  printf("%lld\n", sum);
  return 0;
}
0