結果

問題 No.2685 Cell Proliferation (Easy)
ユーザー ks2mks2m
提出日時 2024-03-20 22:58:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 1,880 bytes
コンパイル時間 3,415 ms
コンパイル使用メモリ 77,676 KB
実行使用メモリ 67,056 KB
最終ジャッジ日時 2024-03-20 22:58:54
合計ジャッジ時間 11,543 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
57,856 KB
testcase_01 AC 322 ms
66,956 KB
testcase_02 AC 145 ms
58,088 KB
testcase_03 AC 245 ms
62,768 KB
testcase_04 AC 260 ms
62,584 KB
testcase_05 AC 219 ms
57,956 KB
testcase_06 AC 222 ms
58,160 KB
testcase_07 AC 235 ms
62,660 KB
testcase_08 AC 240 ms
62,720 KB
testcase_09 AC 276 ms
62,764 KB
testcase_10 AC 241 ms
59,992 KB
testcase_11 AC 208 ms
60,272 KB
testcase_12 AC 207 ms
59,960 KB
testcase_13 AC 237 ms
62,696 KB
testcase_14 AC 249 ms
60,920 KB
testcase_15 AC 342 ms
67,056 KB
testcase_16 AC 245 ms
62,692 KB
testcase_17 AC 138 ms
57,696 KB
testcase_18 AC 215 ms
60,028 KB
testcase_19 AC 223 ms
59,952 KB
testcase_20 AC 215 ms
57,908 KB
testcase_21 AC 149 ms
57,808 KB
testcase_22 AC 300 ms
63,072 KB
testcase_23 AC 207 ms
59,996 KB
testcase_24 AC 318 ms
67,052 KB
testcase_25 AC 297 ms
62,736 KB
testcase_26 AC 243 ms
63,044 KB
testcase_27 AC 173 ms
57,952 KB
testcase_28 AC 250 ms
63,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int p1 = sc.nextInt();
		int p2 = sc.nextInt();
		int q1 = sc.nextInt();
		int q2 = sc.nextInt();
		int t = sc.nextInt();
		sc.close();

//		double p12 = (double) p1 / p2;
//		double q12 = (double) q1 / q2;
//		double[] b = new double[t + 1];
//		b[0] = 1;
//		double[][] r = new double[t + 1][t + 1];
//		r[0][0] = 1;
//		for (int i = 1; i <= t; i++) {
//			for (int j = 0; j < i; j++) {
//				b[i] += r[i - 1][j] * p12;
//			}
//			for (int j = 0; j < i; j++) {
//				r[i][j] = r[i - 1][j] * Math.pow(q12, i - j);
//			}
//			r[i][i] = b[i];
//		}
//
//		double ans = 0;
//		for (int j = 0; j < r.length; j++) {
//			ans += r[t][j];
//		}
//		System.out.println(ans);

		int mod = 998244353;
		long p12 = p1 * modinv(p2, mod) % mod;
		long q12 = q1 * modinv(q2, mod) % mod;

		long[] b = new long[t + 1];
		b[0] = 1;
		long[][] r = new long[t + 1][t + 1];
		r[0][0] = 1;
		for (int i = 1; i <= t; i++) {
			for (int j = 0; j < i; j++) {
				b[i] += r[i - 1][j] * p12 % mod;
			}
			b[i] %= mod;
			for (int j = 0; j < i; j++) {
				r[i][j] = r[i - 1][j] * power(q12, i - j, mod) % mod;
			}
			r[i][i] = b[i];
		}

		long ans = 0;
		for (int j = 0; j < r.length; j++) {
			ans += r[t][j];
		}
		ans %= mod;
		System.out.println(ans);
	}

	static long modinv(long a, int m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}

	static long power(long x, long n, int m) {
		if (n == 0) {
			return 1;
		}
		long val = power(x, n / 2, m);
		val = val * val % m;
		if (n % 2 == 1) {
			x %= m;
			val = val * x % m;
		}
		return val;
	}
}
0