結果
問題 | No.856 増える演算 |
ユーザー | 37zigen |
提出日時 | 2019-07-27 10:59:51 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,365 ms / 3,153 ms |
コード長 | 3,625 bytes |
コンパイル時間 | 3,161 ms |
コンパイル使用メモリ | 79,452 KB |
実行使用メモリ | 96,972 KB |
最終ジャッジ日時 | 2024-07-02 10:57:21 |
合計ジャッジ時間 | 64,855 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 420 ms
76,604 KB |
testcase_01 | AC | 436 ms
76,776 KB |
testcase_02 | AC | 442 ms
76,536 KB |
testcase_03 | AC | 436 ms
76,432 KB |
testcase_04 | AC | 451 ms
76,384 KB |
testcase_05 | AC | 455 ms
76,308 KB |
testcase_06 | AC | 430 ms
76,180 KB |
testcase_07 | AC | 442 ms
76,884 KB |
testcase_08 | AC | 440 ms
76,548 KB |
testcase_09 | AC | 438 ms
76,612 KB |
testcase_10 | AC | 442 ms
76,824 KB |
testcase_11 | AC | 444 ms
76,664 KB |
testcase_12 | AC | 433 ms
76,448 KB |
testcase_13 | AC | 450 ms
76,284 KB |
testcase_14 | AC | 450 ms
76,072 KB |
testcase_15 | AC | 456 ms
76,532 KB |
testcase_16 | AC | 459 ms
75,772 KB |
testcase_17 | AC | 457 ms
76,316 KB |
testcase_18 | AC | 451 ms
76,224 KB |
testcase_19 | AC | 441 ms
76,176 KB |
testcase_20 | AC | 440 ms
76,444 KB |
testcase_21 | AC | 449 ms
76,160 KB |
testcase_22 | AC | 446 ms
76,160 KB |
testcase_23 | AC | 532 ms
73,972 KB |
testcase_24 | AC | 592 ms
83,724 KB |
testcase_25 | AC | 545 ms
79,472 KB |
testcase_26 | AC | 446 ms
74,992 KB |
testcase_27 | AC | 452 ms
76,236 KB |
testcase_28 | AC | 554 ms
73,796 KB |
testcase_29 | AC | 585 ms
84,452 KB |
testcase_30 | AC | 586 ms
83,688 KB |
testcase_31 | AC | 563 ms
79,204 KB |
testcase_32 | AC | 577 ms
81,716 KB |
testcase_33 | AC | 625 ms
79,356 KB |
testcase_34 | AC | 711 ms
83,052 KB |
testcase_35 | AC | 655 ms
79,748 KB |
testcase_36 | AC | 719 ms
80,020 KB |
testcase_37 | AC | 709 ms
79,780 KB |
testcase_38 | AC | 530 ms
73,368 KB |
testcase_39 | AC | 548 ms
83,876 KB |
testcase_40 | AC | 607 ms
76,588 KB |
testcase_41 | AC | 617 ms
81,432 KB |
testcase_42 | AC | 761 ms
80,256 KB |
testcase_43 | AC | 613 ms
84,588 KB |
testcase_44 | AC | 439 ms
74,492 KB |
testcase_45 | AC | 570 ms
84,560 KB |
testcase_46 | AC | 615 ms
75,476 KB |
testcase_47 | AC | 609 ms
85,052 KB |
testcase_48 | AC | 635 ms
84,176 KB |
testcase_49 | AC | 596 ms
80,236 KB |
testcase_50 | AC | 699 ms
74,988 KB |
testcase_51 | AC | 695 ms
80,268 KB |
testcase_52 | AC | 781 ms
84,716 KB |
testcase_53 | AC | 879 ms
89,716 KB |
testcase_54 | AC | 710 ms
79,916 KB |
testcase_55 | AC | 868 ms
93,020 KB |
testcase_56 | AC | 682 ms
82,416 KB |
testcase_57 | AC | 1,035 ms
80,748 KB |
testcase_58 | AC | 862 ms
84,704 KB |
testcase_59 | AC | 1,188 ms
90,436 KB |
testcase_60 | AC | 795 ms
84,688 KB |
testcase_61 | AC | 1,263 ms
96,444 KB |
testcase_62 | AC | 1,207 ms
89,684 KB |
testcase_63 | AC | 534 ms
82,012 KB |
testcase_64 | AC | 1,120 ms
95,664 KB |
testcase_65 | AC | 714 ms
81,172 KB |
testcase_66 | AC | 793 ms
75,156 KB |
testcase_67 | AC | 803 ms
77,280 KB |
testcase_68 | AC | 1,207 ms
90,832 KB |
testcase_69 | AC | 1,212 ms
94,976 KB |
testcase_70 | AC | 1,158 ms
84,664 KB |
testcase_71 | AC | 1,200 ms
95,904 KB |
testcase_72 | AC | 1,112 ms
86,412 KB |
testcase_73 | AC | 1,325 ms
96,596 KB |
testcase_74 | AC | 1,248 ms
90,548 KB |
testcase_75 | AC | 1,170 ms
96,704 KB |
testcase_76 | AC | 1,246 ms
96,972 KB |
testcase_77 | AC | 1,313 ms
90,676 KB |
testcase_78 | AC | 1,178 ms
90,352 KB |
testcase_79 | AC | 1,203 ms
96,676 KB |
testcase_80 | AC | 1,312 ms
90,424 KB |
testcase_81 | AC | 1,365 ms
95,892 KB |
testcase_82 | AC | 1,192 ms
93,620 KB |
ソースコード
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 - 1; } long[] cnt = new long[100000 + 1]; for (int i = 0; i < N; ++i) cnt[A[i]]++; long[] 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) % MOD * 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 long[] mul(long[] a, long[] 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; } long[] ret = new long[ac.length]; for (int i = 0; i < ret.length; ++i) { ret[i] = (long) 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); } } }