結果
問題 |
No.2872 Depth of the Parentheses
|
ユーザー |
![]() |
提出日時 | 2024-09-09 10:28:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 114 ms / 2,000 ms |
コード長 | 2,464 bytes |
コンパイル時間 | 3,610 ms |
コンパイル使用メモリ | 78,816 KB |
実行使用メモリ | 51,612 KB |
最終ジャッジ日時 | 2024-09-09 10:28:31 |
合計ジャッジ時間 | 6,959 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 WA * 4 |
ソースコード
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(); long face = n * pow(100, MOD - 2) % MOD; long back = (1 - face + MOD) % MOD; int k = sc.nextInt(); long rate = pow(face, k) * pow(back, k) % MOD; long ans = 0; for (int i = 0; i < (1 << (k * 2)); i++) { if (getPop(i) != k) { continue; } int current = 0; int depth = 0; for (int j = 0; j < k * 2; j++) { if ((i & (1 << j)) == 0) { current++; depth = Math.max(depth, current); } else { current--; if (current < 0) { depth = 0; break; } } } if (depth == 0 || current != 0) { continue; } ans += rate * depth % MOD; ans %= MOD; } System.out.println(ans); } static long pow(long x, int p) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x % MOD, p / 2); } else { return pow(x, p - 1) * x % MOD; } } static int getPop(int x) { int pop = 0; while (x > 0) { pop += x % 2; x >>= 1; } return pop; } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); 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(); } } }