結果

問題 No.766 金魚すくい
ユーザー 37zigen37zigen
提出日時 2018-12-23 09:48:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 355 ms / 1,500 ms
コード長 3,634 bytes
コンパイル時間 5,039 ms
コンパイル使用メモリ 78,264 KB
実行使用メモリ 52,064 KB
最終ジャッジ日時 2024-09-25 10:29:13
合計ジャッジ時間 14,776 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
49,324 KB
testcase_01 AC 153 ms
49,316 KB
testcase_02 AC 151 ms
49,456 KB
testcase_03 AC 142 ms
49,144 KB
testcase_04 AC 150 ms
49,456 KB
testcase_05 AC 145 ms
49,416 KB
testcase_06 AC 139 ms
49,108 KB
testcase_07 AC 152 ms
49,532 KB
testcase_08 AC 151 ms
49,376 KB
testcase_09 AC 150 ms
49,664 KB
testcase_10 AC 150 ms
49,488 KB
testcase_11 AC 149 ms
49,324 KB
testcase_12 AC 153 ms
49,316 KB
testcase_13 AC 155 ms
49,308 KB
testcase_14 AC 162 ms
49,416 KB
testcase_15 AC 162 ms
49,356 KB
testcase_16 AC 165 ms
49,532 KB
testcase_17 AC 154 ms
49,464 KB
testcase_18 AC 161 ms
49,632 KB
testcase_19 AC 153 ms
49,528 KB
testcase_20 AC 165 ms
49,412 KB
testcase_21 AC 168 ms
49,752 KB
testcase_22 AC 163 ms
49,448 KB
testcase_23 AC 344 ms
51,896 KB
testcase_24 AC 342 ms
51,844 KB
testcase_25 AC 337 ms
51,352 KB
testcase_26 AC 324 ms
51,892 KB
testcase_27 AC 335 ms
51,884 KB
testcase_28 AC 321 ms
51,492 KB
testcase_29 AC 342 ms
51,912 KB
testcase_30 AC 338 ms
52,064 KB
testcase_31 AC 343 ms
51,784 KB
testcase_32 AC 326 ms
51,892 KB
testcase_33 AC 307 ms
51,772 KB
testcase_34 AC 316 ms
51,888 KB
testcase_35 AC 166 ms
49,476 KB
testcase_36 AC 164 ms
49,656 KB
testcase_37 AC 322 ms
51,492 KB
testcase_38 AC 355 ms
51,876 KB
testcase_39 AC 323 ms
51,636 KB
testcase_40 AC 347 ms
52,012 KB
testcase_41 AC 253 ms
51,512 KB
testcase_42 AC 240 ms
50,136 KB
testcase_43 AC 151 ms
49,400 KB
testcase_44 AC 145 ms
49,664 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