結果
問題 | No.1084 積の積 |
ユーザー | kibuna |
提出日時 | 2020-06-19 22:06:44 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 2,859 bytes |
コンパイル時間 | 1,568 ms |
コンパイル使用メモリ | 171,036 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-03 14:48:35 |
合計ジャッジ時間 | 2,802 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 26 ms
6,940 KB |
testcase_05 | AC | 7 ms
6,940 KB |
testcase_06 | AC | 25 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 12 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 8 ms
6,940 KB |
testcase_13 | AC | 15 ms
6,940 KB |
testcase_14 | AC | 7 ms
6,940 KB |
testcase_15 | AC | 6 ms
6,940 KB |
testcase_16 | AC | 16 ms
6,940 KB |
testcase_17 | AC | 7 ms
6,944 KB |
testcase_18 | AC | 11 ms
6,940 KB |
testcase_19 | AC | 15 ms
6,940 KB |
testcase_20 | AC | 5 ms
6,940 KB |
testcase_21 | AC | 6 ms
6,944 KB |
testcase_22 | AC | 5 ms
6,944 KB |
testcase_23 | AC | 9 ms
6,940 KB |
testcase_24 | AC | 8 ms
6,944 KB |
testcase_25 | AC | 14 ms
6,940 KB |
testcase_26 | AC | 13 ms
6,940 KB |
testcase_27 | AC | 12 ms
6,940 KB |
testcase_28 | AC | 13 ms
6,944 KB |
testcase_29 | AC | 13 ms
6,940 KB |
testcase_30 | AC | 13 ms
6,940 KB |
testcase_31 | AC | 13 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 1000000007; template <int mod> struct modint { lint v; modint() : v(0) {} modint(signed v) : v(v) {} modint(lint t) { v = t % mod; if (v < 0) v += mod; } modint pow(lint k) { modint res(1), tmp(v); while (k) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } static modint add_identity() { return modint(0); } static modint mul_identity() { return modint(1); } modint inv() { return pow(mod - 2); } modint &operator+=(modint a) { v += a.v; if (v >= mod) v -= mod; return *this; } modint &operator-=(modint a) { v += mod - a.v; if (v >= mod) v -= mod; return *this; } modint &operator*=(modint a) { v = v * a.v % mod; return *this; } modint &operator/=(modint a) { return (*this) *= a.inv(); } modint operator+(modint a) const { return modint(v) += a; }; modint operator-(modint a) const { return modint(v) -= a; }; modint operator*(modint a) const { return modint(v) *= a; }; modint operator/(modint a) const { return modint(v) /= a; }; modint operator-() const { return v ? modint(mod - v) : modint(v); } bool operator==(const modint a) const { return v == a.v; } bool operator!=(const modint a) const { return v != a.v; } bool operator<(const modint a) const { return v < a.v; } }; using mint = modint<mod>; ostream &operator<<(ostream &os, mint m) { return os << m.v; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); lint n; cin >> n; vector<lint> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < n; ++i) { if (a[i] == 0) { cout << 0 << "\n"; return 0; } } lint curr = 1; lint l = 0; vector<lint> ri(n + 1, 0), ri2(n + 1, 0); for (int i = 0; i < n; ++i) { while (l < n && curr < 1000000000) { curr *= a[l]; l++; } if (curr >= 1000000000) { if (i) ri2[i - 1] -= (n - 1 - (l - 2)); ri[l - 2]--; ri[n - 1]++; } curr /= a[i]; } for (int i = n - 1; i >= 0; --i) { ri[i] += ri[i + 1]; ri2[i] += ri2[i + 1]; } for (int i = n - 1; i >= 0; --i) { ri[i] += ri[i + 1]; } mint ret = 1; for (int i = 0; i < n; ++i) { ret *= mint(a[i]).pow((i + 1) * (n - i) - ri[i] - ri2[i]); } // for (int i = 0; i < n; ++i) { // ret /= mint(a[i]).pow(ri[i] + ri2[i]); // } cout << ret << "\n"; return 0; }