結果

問題 No.2388 At Least K-Characters
ユーザー 👑 chro_96chro_96
提出日時 2023-07-21 22:54:38
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 62 ms / 4,000 ms
コード長 1,095 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 29,584 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 12:57:21
合計ジャッジ時間 4,351 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 56 ms
4,376 KB
testcase_17 AC 53 ms
4,376 KB
testcase_18 AC 57 ms
4,380 KB
testcase_19 AC 57 ms
4,376 KB
testcase_20 AC 60 ms
4,376 KB
testcase_21 AC 62 ms
4,376 KB
testcase_22 AC 61 ms
4,380 KB
testcase_23 AC 61 ms
4,380 KB
testcase_24 AC 60 ms
4,376 KB
testcase_25 AC 57 ms
4,376 KB
testcase_26 AC 60 ms
4,380 KB
testcase_27 AC 60 ms
4,380 KB
testcase_28 AC 61 ms
4,380 KB
testcase_29 AC 60 ms
4,380 KB
testcase_30 AC 60 ms
4,376 KB
testcase_31 AC 57 ms
4,376 KB
testcase_32 AC 57 ms
4,380 KB
testcase_33 AC 56 ms
4,380 KB
testcase_34 AC 61 ms
4,380 KB
testcase_35 AC 62 ms
4,376 KB
testcase_36 AC 60 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int n = 0;
  int m = 0;
  int k = 0;
  char s[500001] = "";
    
  int res = 0;
  
  long long ans = 0LL;
  long long mod_num = 998244353LL;
  
  long long cnt[26] = {};
  long long work[26] = {};
  
  int flag[26] = {};
  int tmp = 0;
  
  res = scanf("%d", &n);
  res = scanf("%d", &m);
  res = scanf("%d", &k);
  res = scanf("%s", s);
  
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 26; j++) {
      work[j] += cnt[j]*((long long)(j+1));
    }
    for (int j = 0; j < 25; j++) {
      work[j+1] += cnt[j]*((long long)(25-j));
    }
    for (int j = 0; j < (int)(s[i]-'a'); j++) {
      if (flag[j] > 0) {
        work[tmp-1] += 1LL;
      } else {
        work[tmp] += 1LL;
      }
    }
    for (int j = 0; j < 26; j++) {
      cnt[j] = work[j]%mod_num;
      work[j] = 0LL;
    }
    for (int j = k-1; j < 26; j++) {
      ans += cnt[j];
    }
    if (flag[(int)(s[i]-'a')] <= 0) {
      flag[(int)(s[i]-'a')] = 1;
      tmp++;
    }
    if (tmp >= k && i < n-1) {
      ans += 1LL;
    }
  }
  
  printf("%lld\n", ans%mod_num);
  return 0;
}
0