結果
問題 | No.1681 +-* |
ユーザー |
|
提出日時 | 2021-09-17 22:53:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 111 ms / 2,000 ms |
コード長 | 973 bytes |
コンパイル時間 | 1,605 ms |
コンパイル使用メモリ | 170,732 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-29 21:40:38 |
合計ジャッジ時間 | 3,812 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define INF ((1LL<<62)-(1LL<<31)) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() typedef long long ll; typedef pair<ll,ll> pl; const ll mod=1000000007; ll modpow(ll n,ll r) { ll num=1; while(r) { if(r&1) num=num*n%mod; n=n*n%mod; r/=2; } return num; } int main() { ll n; cin >> n; vector<ll> a(n); ll tot=1; rep(i,n) { cin >> a[i]; if(a[i]==0) continue; tot*=a[i]; tot%=mod; } reverse(all(a)); ll ans=tot,num=2; if(a[0]!=0) { tot*=modpow(a[0],mod-2); tot%=mod; } else ans=0; for(int i=1;i<n;i++) { ans=(ans+(tot*num)%mod)%mod; if(a[i]!=0) { tot*=modpow(a[i],mod-2); tot%=mod; } else ans=0; num*=3; num%=mod; } cout << ans << endl; return 0; }