結果

問題 No.1084 積の積
ユーザー 👑 jupirojupiro
提出日時 2020-06-19 22:00:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,521 bytes
コンパイル時間 1,067 ms
コンパイル使用メモリ 117,112 KB
実行使用メモリ 4,812 KB
最終ジャッジ日時 2023-09-16 14:10:26
合計ジャッジ時間 3,649 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 59 ms
4,476 KB
testcase_05 RE -
testcase_06 AC 59 ms
4,612 KB
testcase_07 RE -
testcase_08 AC 2 ms
4,380 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 34 ms
4,380 KB
testcase_14 AC 13 ms
4,376 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 40 ms
4,584 KB
testcase_17 AC 16 ms
4,380 KB
testcase_18 AC 26 ms
4,376 KB
testcase_19 AC 35 ms
4,376 KB
testcase_20 AC 9 ms
4,376 KB
testcase_21 AC 13 ms
4,380 KB
testcase_22 AC 11 ms
4,376 KB
testcase_23 AC 21 ms
4,376 KB
testcase_24 AC 19 ms
4,380 KB
testcase_25 AC 35 ms
4,452 KB
testcase_26 AC 37 ms
4,544 KB
testcase_27 AC 37 ms
4,804 KB
testcase_28 AC 37 ms
4,632 KB
testcase_29 AC 37 ms
4,540 KB
testcase_30 AC 37 ms
4,548 KB
testcase_31 AC 36 ms
4,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

struct mint {
	long long x;
	mint(long long x = 0) :x((x% mod + mod) % mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */
	constexpr ll b = inf - 7;
    ll n; scanf("%lld", &n);
    vector<ll> a(n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	vector<mint> pr(n + 1, 1); for (int i = 0; i < n; i++) pr[i + 1] = pr[i] * a[i];
	mint res = 1;
	ll cur = 1;
	mint rui = 1;
	int right = 0;
	for (int left = 0; left < n; left++) {
		while (right < n and cur * a[right] < b) {
			cur *= a[right];
			rui *= cur;
			right++;
		}
		res *= rui;
		if (left == right) right++;
		else cur /= a[left], rui /= mint(a[left]).pow(right - left);
	}
	cout << res.x << "\n";
    return 0;
}
0