結果

問題 No.856 増える演算
ユーザー 37zigen37zigen
提出日時 2019-07-27 10:14:30
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 3,448 bytes
コンパイル時間 2,486 ms
コンパイル使用メモリ 79,264 KB
実行使用メモリ 96,336 KB
最終ジャッジ日時 2024-07-02 10:52:45
合計ジャッジ時間 76,437 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 522 ms
71,500 KB
testcase_01 AC 524 ms
71,128 KB
testcase_02 AC 509 ms
71,440 KB
testcase_03 WA -
testcase_04 AC 513 ms
71,336 KB
testcase_05 AC 516 ms
71,228 KB
testcase_06 WA -
testcase_07 AC 507 ms
71,408 KB
testcase_08 AC 519 ms
71,112 KB
testcase_09 AC 519 ms
71,344 KB
testcase_10 AC 506 ms
71,332 KB
testcase_11 AC 501 ms
71,528 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 520 ms
71,576 KB
testcase_20 AC 520 ms
75,724 KB
testcase_21 AC 513 ms
71,516 KB
testcase_22 AC 513 ms
75,944 KB
testcase_23 AC 613 ms
73,148 KB
testcase_24 AC 681 ms
84,080 KB
testcase_25 AC 634 ms
78,848 KB
testcase_26 AC 540 ms
75,688 KB
testcase_27 AC 531 ms
75,856 KB
testcase_28 AC 619 ms
79,304 KB
testcase_29 AC 655 ms
83,500 KB
testcase_30 AC 647 ms
83,540 KB
testcase_31 AC 587 ms
78,772 KB
testcase_32 AC 581 ms
73,148 KB
testcase_33 AC 813 ms
79,548 KB
testcase_34 AC 936 ms
74,176 KB
testcase_35 AC 834 ms
73,252 KB
testcase_36 AC 877 ms
74,168 KB
testcase_37 AC 895 ms
79,988 KB
testcase_38 AC 531 ms
71,848 KB
testcase_39 AC 639 ms
83,340 KB
testcase_40 AC 717 ms
83,724 KB
testcase_41 AC 746 ms
84,000 KB
testcase_42 AC 933 ms
74,168 KB
testcase_43 AC 760 ms
83,900 KB
testcase_44 AC 512 ms
75,864 KB
testcase_45 AC 679 ms
84,468 KB
testcase_46 AC 696 ms
72,664 KB
testcase_47 AC 669 ms
72,480 KB
testcase_48 AC 815 ms
73,092 KB
testcase_49 AC 718 ms
79,052 KB
testcase_50 AC 816 ms
83,960 KB
testcase_51 AC 935 ms
80,132 KB
testcase_52 AC 951 ms
83,544 KB
testcase_53 WA -
testcase_54 AC 872 ms
73,192 KB
testcase_55 WA -
testcase_56 AC 864 ms
79,428 KB
testcase_57 AC 1,230 ms
89,528 KB
testcase_58 AC 1,139 ms
76,760 KB
testcase_59 AC 1,461 ms
83,260 KB
testcase_60 WA -
testcase_61 AC 1,440 ms
95,340 KB
testcase_62 AC 1,391 ms
89,872 KB
testcase_63 AC 585 ms
83,592 KB
testcase_64 AC 1,265 ms
92,656 KB
testcase_65 WA -
testcase_66 AC 932 ms
78,144 KB
testcase_67 WA -
testcase_68 AC 1,403 ms
83,708 KB
testcase_69 AC 1,319 ms
94,632 KB
testcase_70 AC 1,453 ms
91,216 KB
testcase_71 AC 1,404 ms
94,584 KB
testcase_72 WA -
testcase_73 AC 1,493 ms
95,968 KB
testcase_74 AC 1,439 ms
89,956 KB
testcase_75 WA -
testcase_76 AC 1,393 ms
91,472 KB
testcase_77 AC 1,504 ms
91,356 KB
testcase_78 WA -
testcase_79 AC 1,492 ms
96,336 KB
testcase_80 AC 1,568 ms
95,912 KB
testcase_81 AC 1,457 ms
91,336 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;
		}
		
		Arrays.sort(A);
		if (A[0] <= 2)
			ans = ans * inv((A[0] + A[1]) * pow(A[0], A[1]) % MOD) % MOD;
		else
			ans = ans * inv((A[0] + A[1]) * pow(A[1], A[0]) % MOD) % 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