結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 6 ms
7,808 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 7 ms
11,936 KB
testcase_15 AC 6 ms
8,560 KB
testcase_16 AC 8 ms
12,288 KB
testcase_17 AC 4 ms
5,888 KB
testcase_18 AC 7 ms
12,800 KB
testcase_19 AC 10 ms
13,112 KB
testcase_20 AC 5 ms
6,144 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 13 ms
23,680 KB
testcase_23 AC 19 ms
23,680 KB
testcase_24 AC 19 ms
23,552 KB
testcase_25 AC 19 ms
23,552 KB
testcase_26 AC 4 ms
5,632 KB
testcase_27 AC 20 ms
23,680 KB
testcase_28 AC 19 ms
23,680 KB
testcase_29 AC 20 ms
23,552 KB
testcase_30 AC 19 ms
23,552 KB
testcase_31 AC 19 ms
23,680 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