結果

問題 No.1084 積の積
ユーザー firiexp
提出日時 2020-06-19 21:51:17
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,238 bytes
コンパイル時間 3,844 ms
コンパイル使用メモリ 130,252 KB
最終ジャッジ日時 2025-01-11 06:07:09
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
template <class T>
T pow_ (T x, T n, int M){
uint64_t u = 1, xx = x;
while (n > 0){
if (n&1) u = u * xx % M;
xx = xx * xx % M;
n >>= 1;
}
return static_cast<T>(u);
};
int main() {
int n;
cin >> n;
vector<int> v(n);
for (auto &&i : v) scanf("%d", &i);
for (int i = 0; i < n; ++i) {
if(v[i] == 0){
cout << 0 << "\n";
return 0;
}
}
vector<int> r(n, n);
for (int j = n-2; j >= 0; --j) {
r[j] = r[j+1];
if(v[j+1] != 1) r[j] = j+1;
}
ll ans = 1;
for (int i = 0; i < n; ++i) {
ll val = 1;
for (int j = i; j < n; j = r[j]) {
val *= v[j];
if(val >= 1'000'000'000) break;
ans *= pow_(val, ll(r[j]-j), MOD);
ans %= MOD;
}
}
cout << ans << "\n";
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0