結果
問題 | No.2636 No Waiting in Vain |
ユーザー | tenten |
提出日時 | 2024-02-29 11:15:09 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,505 bytes |
コンパイル時間 | 5,005 ms |
コンパイル使用メモリ | 78,312 KB |
実行使用メモリ | 54,660 KB |
最終ジャッジ日時 | 2024-09-29 12:39:42 |
合計ジャッジ時間 | 9,416 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
50,324 KB |
testcase_01 | RE | - |
testcase_02 | AC | 48 ms
50,452 KB |
testcase_03 | AC | 47 ms
50,436 KB |
testcase_04 | AC | 134 ms
54,368 KB |
testcase_05 | AC | 129 ms
54,620 KB |
testcase_06 | AC | 127 ms
54,200 KB |
testcase_07 | AC | 138 ms
54,488 KB |
testcase_08 | AC | 128 ms
54,436 KB |
testcase_09 | AC | 133 ms
54,280 KB |
testcase_10 | AC | 133 ms
54,420 KB |
testcase_11 | AC | 127 ms
54,188 KB |
testcase_12 | AC | 131 ms
54,284 KB |
testcase_13 | AC | 133 ms
54,588 KB |
testcase_14 | AC | 128 ms
53,992 KB |
testcase_15 | AC | 133 ms
54,308 KB |
testcase_16 | AC | 124 ms
54,420 KB |
testcase_17 | AC | 131 ms
54,492 KB |
testcase_18 | AC | 125 ms
54,516 KB |
testcase_19 | AC | 131 ms
54,660 KB |
testcase_20 | AC | 134 ms
54,228 KB |
testcase_21 | AC | 133 ms
54,108 KB |
testcase_22 | AC | 124 ms
54,188 KB |
testcase_23 | AC | 133 ms
54,316 KB |
testcase_24 | AC | 48 ms
50,392 KB |
testcase_25 | AC | 48 ms
50,304 KB |
testcase_26 | AC | 48 ms
50,064 KB |
testcase_27 | AC | 48 ms
50,392 KB |
testcase_28 | AC | 48 ms
50,344 KB |
testcase_29 | AC | 48 ms
50,152 KB |
testcase_30 | AC | 47 ms
50,280 KB |
testcase_31 | AC | 47 ms
50,396 KB |
testcase_32 | AC | 48 ms
50,268 KB |
testcase_33 | AC | 48 ms
50,304 KB |
testcase_34 | AC | 47 ms
50,168 KB |
testcase_35 | AC | 47 ms
50,268 KB |
testcase_36 | AC | 47 ms
50,060 KB |
testcase_37 | AC | 47 ms
50,060 KB |
testcase_38 | AC | 48 ms
50,436 KB |
testcase_39 | AC | 47 ms
50,068 KB |
testcase_40 | AC | 48 ms
50,432 KB |
testcase_41 | AC | 46 ms
50,412 KB |
testcase_42 | AC | 47 ms
50,468 KB |
testcase_43 | AC | 48 ms
50,496 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 + 1); 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(); } } }