結果

問題 No.1334 Multiply or Add
ユーザー chocoruskchocorusk
提出日時 2021-01-09 20:55:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,702 bytes
コンパイル時間 1,302 ms
コンパイル使用メモリ 135,328 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-04-29 09:31:36
合計ジャッジ時間 6,055 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 44 ms
8,192 KB
testcase_04 AC 44 ms
8,064 KB
testcase_05 AC 44 ms
8,192 KB
testcase_06 AC 46 ms
8,064 KB
testcase_07 AC 44 ms
8,192 KB
testcase_08 AC 46 ms
8,064 KB
testcase_09 AC 44 ms
8,192 KB
testcase_10 AC 44 ms
8,064 KB
testcase_11 AC 45 ms
8,064 KB
testcase_12 AC 46 ms
8,192 KB
testcase_13 AC 47 ms
8,064 KB
testcase_14 AC 47 ms
8,064 KB
testcase_15 AC 47 ms
8,064 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 44 ms
8,064 KB
testcase_20 AC 44 ms
8,192 KB
testcase_21 AC 44 ms
8,064 KB
testcase_22 AC 47 ms
8,064 KB
testcase_23 AC 43 ms
8,192 KB
testcase_24 AC 47 ms
8,064 KB
testcase_25 AC 45 ms
8,192 KB
testcase_26 AC 45 ms
8,064 KB
testcase_27 AC 47 ms
8,064 KB
testcase_28 AC 45 ms
8,064 KB
testcase_29 AC 44 ms
8,064 KB
testcase_30 AC 44 ms
8,192 KB
testcase_31 AC 44 ms
8,064 KB
testcase_32 AC 46 ms
8,064 KB
testcase_33 AC 48 ms
8,192 KB
testcase_34 AC 44 ms
8,064 KB
testcase_35 AC 44 ms
8,064 KB
testcase_36 AC 44 ms
8,064 KB
testcase_37 AC 44 ms
8,064 KB
testcase_38 AC 44 ms
8,192 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 20 ms
5,376 KB
testcase_41 AC 8 ms
5,376 KB
testcase_42 AC 9 ms
5,376 KB
testcase_43 AC 36 ms
7,040 KB
testcase_44 AC 21 ms
5,376 KB
testcase_45 AC 9 ms
5,376 KB
testcase_46 AC 22 ms
5,504 KB
testcase_47 AC 32 ms
6,400 KB
testcase_48 AC 23 ms
5,632 KB
testcase_49 AC 43 ms
7,552 KB
testcase_50 AC 81 ms
5,376 KB
testcase_51 AC 81 ms
5,376 KB
testcase_52 AC 83 ms
5,376 KB
testcase_53 AC 82 ms
5,376 KB
testcase_54 AC 83 ms
5,376 KB
testcase_55 AC 88 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 2 ms
5,376 KB
testcase_58 AC 2 ms
5,248 KB
testcase_59 AC 2 ms
5,376 KB
testcase_60 AC 2 ms
5,376 KB
testcase_61 AC 2 ms
5,376 KB
testcase_62 AC 2 ms
5,376 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 1 ms
5,376 KB
testcase_65 AC 2 ms
5,376 KB
testcase_66 AC 66 ms
5,376 KB
testcase_67 AC 44 ms
5,376 KB
testcase_68 AC 4 ms
5,376 KB
testcase_69 AC 76 ms
5,376 KB
testcase_70 AC 72 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
    int n; cin>>n;
    ll a[200020];
    ll tot=1;
    for(int i=0; i<n; i++){
        cin>>a[i];
        tot=min(MOD, tot*a[i]);
    }
    if(tot==MOD){
        ll ans=1;
        for(int i=0; i<n; i++){
            ans=ans*a[i]%MOD;
        }
        cout<<ans<<endl;
        return 0;
    }
    ll p[200020];
    p[0]=1;
    for(int i=0; i<n; i++){
        p[i+1]=p[i]*a[i];
    }
    using Pl=pair<ll, ll>;
    deque<Pl> deq;
    ll dp[200020];
    dp[0]=0;
    deq.push_back({1, 0});
    for(int i=0; i<n; i++){
        ll x=p[i+1];
        while(deq.size()>1){
            ll a1=deq[0].first, b1=deq[0].second;
            ll a2=deq[1].first, b2=deq[1].second;
            if(x/a1+b1>x/a2+b2) break;
            deq.pop_front();
        }
        dp[i+1]=x/deq[0].first+deq[0].second;
        ll a0=p[i+1], b0=dp[i+1];
        while(deq.size()>1){
            ll a1=deq[0].first, b1=deq[0].second;
            ll a2=deq[1].first, b2=deq[1].second;
            if((b1-b2)*a2*(a0-a1)>(b0-b1)*a0*(a1-a2)) break;
            deq.pop_front();
        }
        deq.push_front({a0, b0});
    }
    cout<<dp[n]<<endl;
    return 0;
}
0