結果

問題 No.1334 Multiply or Add
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2020-11-06 11:56:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,684 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 79,832 KB
実行使用メモリ 5,036 KB
最終ジャッジ日時 2023-09-29 21:23:11
合計ジャッジ時間 5,190 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 30 ms
4,672 KB
testcase_04 AC 32 ms
4,860 KB
testcase_05 AC 31 ms
4,812 KB
testcase_06 AC 32 ms
4,928 KB
testcase_07 AC 30 ms
4,676 KB
testcase_08 AC 31 ms
4,780 KB
testcase_09 AC 29 ms
4,744 KB
testcase_10 AC 30 ms
4,632 KB
testcase_11 AC 29 ms
4,668 KB
testcase_12 AC 33 ms
4,992 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 29 ms
4,728 KB
testcase_17 AC 30 ms
4,624 KB
testcase_18 AC 29 ms
4,628 KB
testcase_19 AC 29 ms
4,660 KB
testcase_20 AC 30 ms
4,612 KB
testcase_21 AC 30 ms
4,672 KB
testcase_22 AC 30 ms
4,772 KB
testcase_23 AC 31 ms
4,748 KB
testcase_24 AC 32 ms
4,920 KB
testcase_25 AC 32 ms
5,036 KB
testcase_26 AC 31 ms
4,844 KB
testcase_27 AC 31 ms
4,688 KB
testcase_28 AC 31 ms
4,692 KB
testcase_29 AC 30 ms
4,576 KB
testcase_30 AC 31 ms
4,844 KB
testcase_31 AC 31 ms
4,904 KB
testcase_32 AC 33 ms
5,000 KB
testcase_33 WA -
testcase_34 AC 31 ms
4,808 KB
testcase_35 AC 32 ms
4,872 KB
testcase_36 AC 32 ms
4,688 KB
testcase_37 AC 32 ms
4,656 KB
testcase_38 AC 32 ms
4,684 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 WA -
testcase_41 AC 6 ms
4,376 KB
testcase_42 AC 7 ms
4,376 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 7 ms
4,380 KB
testcase_46 AC 14 ms
4,376 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 77 ms
4,844 KB
testcase_51 AC 77 ms
4,688 KB
testcase_52 AC 77 ms
4,580 KB
testcase_53 AC 77 ms
4,672 KB
testcase_54 AC 77 ms
4,580 KB
testcase_55 AC 84 ms
4,668 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 3 ms
4,376 KB
testcase_58 AC 3 ms
4,380 KB
testcase_59 AC 3 ms
4,384 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 3 ms
4,376 KB
testcase_62 AC 3 ms
4,376 KB
testcase_63 AC 2 ms
4,376 KB
testcase_64 AC 2 ms
4,376 KB
testcase_65 AC 2 ms
4,376 KB
testcase_66 AC 63 ms
4,456 KB
testcase_67 AC 42 ms
4,376 KB
testcase_68 AC 3 ms
4,380 KB
testcase_69 AC 72 ms
4,376 KB
testcase_70 AC 68 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<cassert>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef vector<lint>vl;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const lint mod=1e9+7;
lint cmul(lint a,lint b){
  a=min(a,mod);
  b=min(b,mod);
  return min(a*b,mod);
}

int n;
vl a;
vl o,num,numcap;
const lint lim=2.5e5,blim=18;
bool dp[blim+1][lim];
int main(){
  cin>>n;
  a.resize(n);
  rep(i,n)cin>>a[i];
  lint sum=0;
  int c1=0;
  lint pr=1,cap=1;
  int ph=0;
  rep(i,n){
    if(a[i]==1){
      if(ph==0){
        c1++;
      }else{
        o.push_back(c1);
        num.push_back(pr);
        numcap.push_back(cap);
        ph=0;
        pr=1;
        cap=1;
        c1=1;
      }
    }else{
      if(ph==0){
        ph=1;
      }
      pr=pr*a[i]%mod;
      cap=cmul(cap,a[i]);
    }
  }
  if(ph==0){
    sum=c1;
  }else{
    o.push_back(c1);
    num.push_back(pr);
    numcap.push_back(cap);
  }
  cerr<<sum<<endl;
  rep(i,o.size()){
    cerr<<" "<<o[i]<<" "<<num[i]<<" ("<<numcap[i]<<")"<<endl;
  }
  lint gpr=1;
  lint gcap=1;
  rep(i,o.size()){
    gpr=gpr*num[i]%mod;
    gcap=cmul(gcap,numcap[i]);
  }
  if(gcap>=lim/2){
    sum+=o[0];
    cout<<(sum+gpr)%mod<<endl;
    return 0;
  }
  assert(o.size()<=blim);
  dp[0][0]=1;
  for(int i=1;i<=(int)o.size();i++){
    rep(j,i){
      lint locpr=1;
      for(int k=j;k<i;k++)locpr*=num[k];
      rep(k,lim){
        if(!dp[j][k])continue;
        assert(k+locpr+o[j]<lim);
        dp[i][k+locpr+o[j]]=1;
        assert(k+locpr<lim);
        dp[i][k+locpr]=1;
      }
    }
  }
  int ma=0;
  rep(i,lim)if(dp[o.size()][i])ma=i;
  cout<<ma+sum<<endl;
}
0