結果

問題 No.1084 積の積
ユーザー cn_449cn_449
提出日時 2020-06-19 21:38:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 2,955 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 114,232 KB
実行使用メモリ 4,816 KB
最終ジャッジ日時 2023-09-16 13:40:32
合計ジャッジ時間 2,703 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 29 ms
4,644 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 28 ms
4,632 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 13 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 15 ms
4,380 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 17 ms
4,544 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 11 ms
4,376 KB
testcase_19 AC 15 ms
4,380 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 7 ms
4,380 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 15 ms
4,380 KB
testcase_26 AC 13 ms
4,552 KB
testcase_27 AC 13 ms
4,660 KB
testcase_28 AC 13 ms
4,640 KB
testcase_29 AC 13 ms
4,552 KB
testcase_30 AC 13 ms
4,628 KB
testcase_31 AC 13 ms
4,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 1000000007;
constexpr ll modsize = 0;
vector<ll> fac(modsize);
vector<ll> inv(modsize);
vector<ll> facinv(modsize);

void modcalc() {
	if (modsize == 0) abort();
	fac[0] = 1; fac[1] = 1; inv[1] = 1;
	facinv[0] = 1; facinv[1] = 1;
	for (ll i = 2; i < modsize; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		facinv[i] = facinv[i - 1] * inv[i] % mod;
	}
}

ll modinv(ll a) {
	if (a == 0) abort();
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

ll modpow(ll a, ll b) {
	ll ans = 1;
	a %= mod;
	while (b) {
		if (b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[n - k] % mod;
}

ll modhom(ll n, ll k) {
	if (n < 0 || k < 0 || n == 0 && k > 0) return 0;
	if (n == 0 && k == 0) return 1;
	return fac[n + k - 1] * facinv[k] % mod * facinv[n - 1] % mod;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	rep(i, n) {
		if (a[i] == 0) {
			cout << "0\n";
			return 0;
		}
	}
	vector<ll> cnt(n + 2);
	ll now = 1;
	ll right = 0;
	rep(left, n) {
		while (right < n && now * a[right] < inf) {
			now *= a[right];
			right++;
		}
		cnt[left] += right - left;
		cnt[left + 1] += left - right - 1;
		cnt[right + 1] += 1;
		if (left == right) right++;
		else now /= a[left];
	}
	rep(i, n + 1) cnt[i + 1] += cnt[i];
	rep(i, n + 1) cnt[i + 1] += cnt[i];
	ll ans = 1;
	rep(i, n) {
		ans *= modpow(a[i], cnt[i]);
		ans %= mod;
	}
	cout << ans << '\n';
}
0