結果
問題 | No.1084 積の積 |
ユーザー | kappybar |
提出日時 | 2020-06-20 00:09:44 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 153 ms / 2,000 ms |
コード長 | 2,001 bytes |
コンパイル時間 | 1,709 ms |
コンパイル使用メモリ | 170,396 KB |
実行使用メモリ | 4,996 KB |
最終ジャッジ日時 | 2023-09-16 16:13:02 |
合計ジャッジ時間 | 4,208 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 153 ms
4,992 KB |
testcase_05 | AC | 152 ms
4,996 KB |
testcase_06 | AC | 152 ms
4,912 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 46 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 4 ms
4,380 KB |
testcase_12 | AC | 22 ms
4,380 KB |
testcase_13 | AC | 43 ms
4,380 KB |
testcase_14 | AC | 17 ms
4,380 KB |
testcase_15 | AC | 16 ms
4,376 KB |
testcase_16 | AC | 49 ms
4,376 KB |
testcase_17 | AC | 20 ms
4,376 KB |
testcase_18 | AC | 33 ms
4,376 KB |
testcase_19 | AC | 44 ms
4,376 KB |
testcase_20 | AC | 12 ms
4,376 KB |
testcase_21 | AC | 17 ms
4,376 KB |
testcase_22 | AC | 13 ms
4,380 KB |
testcase_23 | AC | 27 ms
4,376 KB |
testcase_24 | AC | 25 ms
4,380 KB |
testcase_25 | AC | 43 ms
4,376 KB |
testcase_26 | AC | 39 ms
4,380 KB |
testcase_27 | AC | 38 ms
4,376 KB |
testcase_28 | AC | 39 ms
4,376 KB |
testcase_29 | AC | 39 ms
4,380 KB |
testcase_30 | AC | 39 ms
4,376 KB |
testcase_31 | AC | 38 ms
4,376 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; constexpr ll INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; ll n = 100005; vector<ll> a(n); long long modpow(long long x, long long n) { long long ret = 1; while (n > 0) { if (n & 1) ret = (ret * x) % MOD; x = (x * x) % MOD; n >>= 1; } return ret; } ll dfs(ll l,ll r){ if(l==r) return 1; if(l+1==r) return a[l]; ll p1 = dfs(l,(l+r)/2); ll p2 = dfs((l+r)/2,r); ll res = (p1 * p2)%MOD; vector<ll> F,L; ll now = 1; ll m = (l+r)/2; while(1){ if(m>=r) break; now *= a[m]; m ++; if(now < INF) L.push_back(now); else break; } now = 1; m = ((l+r)/2) - 1; while(1){ if(m<l) break; now *= a[m]; m --; if(now < INF) F.push_back(now); else break; } reverse(F.begin(),F.end()); vector<ll> cnt(L.size(),0); rep(i,F.size()){ ll left = -1,right = L.size(); while(right - left > 1){ ll mid = (left + right)/2; if(F[i]*L[mid]<INF) left = mid; else right = mid; } res = (res * modpow(F[i],left+1))%MOD; if(left!=-1) cnt[left] ++; //cout << "left" << left << endl; } ll point = 0; for(ll i=L.size()-1;i>=0;i--){ ll now = cnt[i]; if(i==L.size()-1) cnt[i] = now + point; else cnt[i] = now + cnt[i+1] + point; point += now; } rep(i,L.size()){ res = (res * modpow(a[i+(l+r)/2],cnt[i]))%MOD; } /* rep(i,L.size()){ cout << cnt[i] << " " ; } cout << endl; */ return res; } int main(){ cin >> n; a.resize(n); rep(i,n) cin >> a[i]; cout << dfs(0,n) << endl; return 0; }