結果

問題 No.1084 積の積
ユーザー hirokazu1020
提出日時 2020-06-19 22:08:59
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,498 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 96,844 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-03 14:49:52
合計ジャッジ時間 2,462 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define MOD 1000000007
long long extgcd(int a, int b, int& x, int& y) {
int gcd_ = a;
if (b) {
gcd_ = extgcd(b, a % b, y, x);
y -= a / b * x;
}
else {
x = 1; y = 0;
}
return gcd_;
}
// O(log MOD)
int inv_mod(int a) {
int x, y;
extgcd(a, MOD, x, y);
return (MOD + x % MOD) % MOD;
}
long long pow_mod(long long x, long long y) {
int res = 1;
while (y) {
if (y & 1)res = (res * x) % MOD;
y >>= 1;
x = (x * x) % MOD;
}
return res;
}
int n;
int a[100000];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
rep(i, n)cin >> a[i];
if (find(a,a+n, 0) != a+n) {
cout << 0 << endl;
return 0;
}
long long ans = 1;
long long s = 1, sm = 1;
int e = 0;
rep(i, n) {
while (e < n && s * a[e] < 1000000000) {
s *= a[e];
sm *= s;
sm %= MOD;
e++;
}
ans *= sm;
ans %= MOD;
s /= a[i];
sm = sm * pow_mod(inv_mod(a[i]), e - i) % MOD;
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0