結果

問題 No.856 増える演算
ユーザー 37zigen37zigen
提出日時 2019-07-27 10:35:11
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 3,605 bytes
コンパイル時間 2,315 ms
コンパイル使用メモリ 79,152 KB
実行使用メモリ 103,464 KB
最終ジャッジ日時 2024-07-02 10:54:43
合計ジャッジ時間 66,313 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 439 ms
77,348 KB
testcase_01 AC 450 ms
71,180 KB
testcase_02 AC 439 ms
79,188 KB
testcase_03 AC 458 ms
71,280 KB
testcase_04 AC 429 ms
79,252 KB
testcase_05 AC 434 ms
71,360 KB
testcase_06 AC 457 ms
79,172 KB
testcase_07 AC 461 ms
71,136 KB
testcase_08 AC 462 ms
79,352 KB
testcase_09 AC 440 ms
70,824 KB
testcase_10 AC 456 ms
78,936 KB
testcase_11 AC 448 ms
71,388 KB
testcase_12 AC 436 ms
79,232 KB
testcase_13 AC 455 ms
75,684 KB
testcase_14 AC 455 ms
83,088 KB
testcase_15 AC 453 ms
83,580 KB
testcase_16 AC 459 ms
79,192 KB
testcase_17 AC 451 ms
76,100 KB
testcase_18 AC 435 ms
79,276 KB
testcase_19 AC 463 ms
71,216 KB
testcase_20 AC 448 ms
83,620 KB
testcase_21 AC 452 ms
79,140 KB
testcase_22 AC 457 ms
75,636 KB
testcase_23 AC 559 ms
81,624 KB
testcase_24 AC 596 ms
91,652 KB
testcase_25 AC 544 ms
85,088 KB
testcase_26 AC 448 ms
81,364 KB
testcase_27 AC 453 ms
83,760 KB
testcase_28 AC 573 ms
81,256 KB
testcase_29 AC 609 ms
91,056 KB
testcase_30 AC 576 ms
88,520 KB
testcase_31 AC 527 ms
84,900 KB
testcase_32 AC 553 ms
79,700 KB
testcase_33 AC 648 ms
87,112 KB
testcase_34 AC 788 ms
79,640 KB
testcase_35 AC 627 ms
80,416 KB
testcase_36 AC 716 ms
74,212 KB
testcase_37 AC 658 ms
87,464 KB
testcase_38 AC 507 ms
77,516 KB
testcase_39 AC 546 ms
83,528 KB
testcase_40 AC 605 ms
80,928 KB
testcase_41 AC 604 ms
83,332 KB
testcase_42 AC 715 ms
82,236 KB
testcase_43 AC 652 ms
91,080 KB
testcase_44 AC 464 ms
81,400 KB
testcase_45 AC 574 ms
89,248 KB
testcase_46 AC 641 ms
79,456 KB
testcase_47 AC 597 ms
80,216 KB
testcase_48 AC 660 ms
72,936 KB
testcase_49 AC 601 ms
86,964 KB
testcase_50 AC 703 ms
81,668 KB
testcase_51 AC 711 ms
78,924 KB
testcase_52 AC 780 ms
76,204 KB
testcase_53 AC 854 ms
90,324 KB
testcase_54 AC 729 ms
78,868 KB
testcase_55 AC 1,083 ms
90,204 KB
testcase_56 AC 678 ms
87,932 KB
testcase_57 AC 1,115 ms
88,892 KB
testcase_58 AC 873 ms
90,268 KB
testcase_59 AC 1,330 ms
96,300 KB
testcase_60 AC 828 ms
79,832 KB
testcase_61 AC 1,238 ms
103,052 KB
testcase_62 AC 1,201 ms
96,188 KB
testcase_63 AC 548 ms
87,392 KB
testcase_64 AC 1,254 ms
98,408 KB
testcase_65 AC 655 ms
78,320 KB
testcase_66 AC 736 ms
78,012 KB
testcase_67 AC 837 ms
82,064 KB
testcase_68 AC 1,124 ms
91,388 KB
testcase_69 AC 1,188 ms
101,452 KB
testcase_70 AC 1,215 ms
96,948 KB
testcase_71 AC 1,131 ms
102,612 KB
testcase_72 AC 1,079 ms
84,300 KB
testcase_73 AC 1,353 ms
103,464 KB
testcase_74 AC 1,325 ms
95,924 KB
testcase_75 AC 1,180 ms
95,872 KB
testcase_76 AC 1,248 ms
96,232 KB
testcase_77 AC 1,245 ms
90,332 KB
testcase_78 AC 1,323 ms
90,228 KB
testcase_79 AC 1,393 ms
90,340 KB
testcase_80 AC 1,225 ms
95,880 KB
testcase_81 AC 1,340 ms
91,356 KB
testcase_82 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

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

	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 run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
		}
		long ans = 1;
		long sum = A[N - 1];
		for (int i = N - 2; i >= 0; --i) {
			ans = ans * pow(A[i], sum) % MOD;
			sum += A[i];
		}
		sum %= MOD;
		int[] cnt = new int[100000 + 1];
		for (int i = 0; i < N; ++i)
			cnt[A[i]]++;
		int[] cnt2 = mul(cnt, cnt);
		for (int i = 0; i < N; ++i) {
			cnt2[2 * A[i]]--;
		}
		for (int i = 0; i < cnt2.length; ++i) {
			cnt2[i] /= 2;
			ans = ans * pow(i, cnt2[i]) % MOD;
		}

		long coe = -1;
		double v = Double.MAX_VALUE / 3;
		long min = A[0];
		for (int i = 1; i < N; ++i) {
			if (v > Math.log(A[i] + min) + A[i] * Math.log(min)) {
				v = Math.log(A[i] + min) + A[i] * Math.log(min);
				coe = (A[i] + min) * pow(min, A[i]) % MOD;
			}
			min = Math.min(min, A[i]);
		}

		ans = ans * inv(coe) % MOD;
		System.out.println(ans);
	}

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

	static int[] mul(int[] a, int[] b) {
		int n = 1;
		while (n < a.length + b.length)
			n *= 2;
		Complex[] ac = new Complex[n];
		Complex[] bc = new Complex[n];
		for (int i = 0; i < n; ++i) {
			ac[i] = new Complex(0, 0);
			bc[i] = new Complex(0, 0);
		}
		for (int i = 0; i < a.length; ++i) {
			ac[i].re = a[i];
		}
		for (int i = 0; i < b.length; ++i) {
			bc[i].re = b[i];
		}
		ac = fft(ac, false);
		bc = fft(bc, false);
		for (int i = 0; i < ac.length; ++i) {
			ac[i] = ac[i].mul(bc[i]);
		}
		ac = fft(ac, true);
		for (int i = 0; i < ac.length; ++i) {
			ac[i].re /= n;
			ac[i].co /= n;
		}
		int[] ret = new int[ac.length];
		for (int i = 0; i < ret.length; ++i) {
			ret[i] = (int) Math.round(ac[i].re);
		}
		return ret;

	}

	static Complex[] fft(Complex[] a, boolean rev) {
		int n = a.length;
		if (n == 1)
			return a;
		int c = 0;
		for (int i = 1; i < n; ++i) {
			int j;
			for (j = n >> 1; j > (c ^= j); j >>= 1)
				;
			if (c > i) {
				Complex tmp = a[c];
				a[c] = a[i];
				a[i] = tmp;
			}
		}

		for (int d = 1; d < n; d <<= 1) {
			for (int j = 0; j < d; ++j) {
				double angle = 2 * Math.PI / (2 * d) * (rev ? -1 : 1) * j;
				Complex mul = new Complex(Math.cos(angle), Math.sin(angle));
				for (int pos = 0; pos < n; pos += 2 * d) {
					double ure = a[pos + j].re;
					double uco = a[pos + j].co;
					double vre = a[pos + j + d].re * mul.re - a[pos + j + d].co * mul.co;
					double vco = a[pos + j + d].co * mul.re + a[pos + j + d].re * mul.co;
					a[pos + j].re = ure + vre;
					a[pos + j].co = uco + vco;
					a[pos + j + d].re = ure - vre;
					a[pos + j + d].co = uco - vco;
				}
			}
		}
		return a;
	}

	Complex exp(double a) {
		return new Complex(Math.cos(a), Math.sin(a));
	}

	static class Complex {
		double re, co;

		public Complex(double re, double co) {
			this.re = re;
			this.co = co;
		}

		Complex add(Complex o) {
			return new Complex(re + o.re, co + o.co);
		}

		Complex subtract(Complex o) {
			return new Complex(re - o.re, co - o.co);
		}

		Complex mul(Complex o) {
			return new Complex(re * o.re - co * o.co, re * o.co + o.re * co);
		}
	}
}
0