結果
問題 | No.2636 No Waiting in Vain |
ユーザー | tenten |
提出日時 | 2024-02-29 11:16:53 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 151 ms / 2,000 ms |
コード長 | 2,505 bytes |
コンパイル時間 | 2,181 ms |
コンパイル使用メモリ | 78,896 KB |
実行使用メモリ | 56,276 KB |
最終ジャッジ日時 | 2024-09-29 12:39:53 |
合計ジャッジ時間 | 7,538 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
50,164 KB |
testcase_01 | AC | 53 ms
50,412 KB |
testcase_02 | AC | 52 ms
50,280 KB |
testcase_03 | AC | 53 ms
50,332 KB |
testcase_04 | AC | 144 ms
54,584 KB |
testcase_05 | AC | 144 ms
54,076 KB |
testcase_06 | AC | 146 ms
54,080 KB |
testcase_07 | AC | 151 ms
54,348 KB |
testcase_08 | AC | 137 ms
54,012 KB |
testcase_09 | AC | 143 ms
54,740 KB |
testcase_10 | AC | 140 ms
54,584 KB |
testcase_11 | AC | 143 ms
54,296 KB |
testcase_12 | AC | 146 ms
54,608 KB |
testcase_13 | AC | 144 ms
56,276 KB |
testcase_14 | AC | 138 ms
54,444 KB |
testcase_15 | AC | 142 ms
54,512 KB |
testcase_16 | AC | 136 ms
54,316 KB |
testcase_17 | AC | 145 ms
54,264 KB |
testcase_18 | AC | 140 ms
54,284 KB |
testcase_19 | AC | 143 ms
54,388 KB |
testcase_20 | AC | 132 ms
54,576 KB |
testcase_21 | AC | 146 ms
54,612 KB |
testcase_22 | AC | 141 ms
54,144 KB |
testcase_23 | AC | 143 ms
53,928 KB |
testcase_24 | AC | 54 ms
50,288 KB |
testcase_25 | AC | 53 ms
50,360 KB |
testcase_26 | AC | 55 ms
50,128 KB |
testcase_27 | AC | 54 ms
50,304 KB |
testcase_28 | AC | 55 ms
50,168 KB |
testcase_29 | AC | 54 ms
50,368 KB |
testcase_30 | AC | 52 ms
50,064 KB |
testcase_31 | AC | 52 ms
50,300 KB |
testcase_32 | AC | 53 ms
50,408 KB |
testcase_33 | AC | 53 ms
50,344 KB |
testcase_34 | AC | 52 ms
50,432 KB |
testcase_35 | AC | 53 ms
50,380 KB |
testcase_36 | AC | 53 ms
50,400 KB |
testcase_37 | AC | 54 ms
50,300 KB |
testcase_38 | AC | 56 ms
50,168 KB |
testcase_39 | AC | 55 ms
50,212 KB |
testcase_40 | AC | 54 ms
50,168 KB |
testcase_41 | AC | 53 ms
50,436 KB |
testcase_42 | AC | 55 ms
50,296 KB |
testcase_43 | AC | 53 ms
50,468 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { static final int MOD = 998244353; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int k = sc.nextInt(); char[] input = sc.next().toCharArray(); int count = 0; int target = 0; char prev = 'N'; for (char c : input) { if (c == 'N') { count++; if (prev != 'C') { target++; } } prev = c; } long ans = 0; Combination comb = new Combination(target + 3); for (int i = 1; i <= count - k && i <= target; i++) { ans += comb.getComb(target, i); ans %= MOD; } System.out.println(ans); } } class Combination { static final int MOD = 998244353; long[] fac; long[] finv; long[] inv; public Combination (int size) { fac = new long [size]; finv = new long [size]; inv = new long [size]; fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < size; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } public long getComb(int n, int k) { if (n < k || n < 0 || k < 0) { return 0; } return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }