結果

問題 No.766 金魚すくい
ユーザー 37zigen37zigen
提出日時 2018-12-23 09:48:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 431 ms / 1,500 ms
コード長 3,634 bytes
コンパイル時間 4,737 ms
コンパイル使用メモリ 78,092 KB
実行使用メモリ 67,472 KB
最終ジャッジ日時 2023-10-26 02:26:31
合計ジャッジ時間 19,354 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
62,720 KB
testcase_01 AC 152 ms
62,728 KB
testcase_02 AC 153 ms
62,720 KB
testcase_03 AC 153 ms
62,800 KB
testcase_04 AC 155 ms
62,940 KB
testcase_05 AC 157 ms
62,796 KB
testcase_06 AC 153 ms
62,932 KB
testcase_07 AC 155 ms
62,792 KB
testcase_08 AC 156 ms
62,772 KB
testcase_09 AC 156 ms
62,940 KB
testcase_10 AC 155 ms
62,784 KB
testcase_11 AC 157 ms
62,792 KB
testcase_12 AC 155 ms
62,816 KB
testcase_13 AC 172 ms
63,384 KB
testcase_14 AC 171 ms
63,356 KB
testcase_15 AC 167 ms
63,412 KB
testcase_16 AC 169 ms
63,356 KB
testcase_17 AC 168 ms
63,400 KB
testcase_18 AC 177 ms
63,488 KB
testcase_19 AC 169 ms
62,800 KB
testcase_20 AC 171 ms
62,960 KB
testcase_21 AC 170 ms
63,412 KB
testcase_22 AC 169 ms
63,356 KB
testcase_23 AC 386 ms
66,524 KB
testcase_24 AC 404 ms
66,568 KB
testcase_25 AC 368 ms
66,552 KB
testcase_26 AC 316 ms
66,292 KB
testcase_27 AC 431 ms
67,444 KB
testcase_28 AC 383 ms
66,548 KB
testcase_29 AC 347 ms
66,692 KB
testcase_30 AC 367 ms
66,288 KB
testcase_31 AC 384 ms
66,556 KB
testcase_32 AC 427 ms
67,472 KB
testcase_33 AC 356 ms
66,556 KB
testcase_34 AC 364 ms
67,380 KB
testcase_35 AC 168 ms
63,020 KB
testcase_36 AC 168 ms
63,024 KB
testcase_37 AC 388 ms
66,472 KB
testcase_38 AC 385 ms
66,548 KB
testcase_39 AC 376 ms
66,288 KB
testcase_40 AC 380 ms
66,556 KB
testcase_41 AC 304 ms
66,020 KB
testcase_42 AC 255 ms
64,460 KB
testcase_43 AC 156 ms
62,784 KB
testcase_44 AC 154 ms
62,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	final long MOD = (long) 1e9 + 7;

	long[] fac = new long[300000];
	long[] ifac = new long[fac.length];
	long[] inv = new long[fac.length];
	{
		fac[0] = fac[1] = inv[0] = inv[1] = ifac[0] = ifac[1] = 1;
		for (int i = 2; i < fac.length; ++i) {
			fac[i] = i * fac[i - 1] % MOD;
		}
		for (int i = 2; i < inv.length; ++i) {
			inv[i] = MOD - (MOD / i) * inv[(int) MOD % i] % MOD;
		}
		for (int i = 2; i < ifac.length; ++i) {
			ifac[i] = inv[i] * ifac[i - 1] % MOD;
		}
	}
	long[] p = new long[100001];
	long[] q = new long[100001];

	void run() {
		Scanner sc = new Scanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		int P = sc.nextInt();
		long[] V = new long[N];
		long[] sum = new long[N];
		for (int i = 0; i < N; ++i) {
			V[i] = sc.nextLong();
		}
		Arrays.sort(V);
		for (int i = 0; i < N; ++i) {
			sum[i] = (i > 0 ? sum[i - 1] : 0) + V[N - 1 - i];
			sum[i] %= MOD;
		}
		p[0] = 1;
		q[0] = 1;
		for (int i = 1; i < p.length; ++i) {
			p[i] = p[i - 1] * (100 - P) % MOD * inv(100) % MOD;
			q[i] = q[i - 1] * P % MOD * inv(100) % MOD;
		}
		long ans = 0;
		// 成功回数N回
		// 失敗回数
		for (int i = 0; i < M; ++i) {
			ans += sum[N - 1] * c(N - 1 + i, i) % MOD * p[N] % MOD * q[i] % MOD;
			ans %= MOD;
		}
		// 成功回数
		for (int i = 1; i < N; ++i) {
			ans += sum[i - 1] * c(i + M - 1, i) % MOD * p[i] % MOD * q[M] % MOD;
			ans %= MOD;
		}
		System.out.println(ans);
	}

	long c(int n, int k) {
		return fac[n] * ifac[n - k] % MOD * ifac[k] % MOD;
	}

	long inv(long a) {
		return pow(a, MOD - 2);
	}

	long pow(long a, long n) {
		long ret = 1;
		for (; n > 0; n >>= 1, a = a * a % MOD) {
			if (n % 2 == 1) {
				ret = ret * a % MOD;
			}
		}
		return ret;
	}

	void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

}

class Scanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}
}
0