結果
問題 | No.1334 Multiply or Add |
ユーザー |
👑 ![]() |
提出日時 | 2021-01-16 12:57:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,033 bytes |
コンパイル時間 | 2,786 ms |
コンパイル使用メモリ | 195,432 KB |
最終ジャッジ日時 | 2025-01-17 21:27:47 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 66 WA * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:13:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | scanf("%d",&N); | ~~~~~^~~~~~~~~ main.cpp:14:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | rep(i,N) scanf("%d",&A[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) const ULL M=1000000007; int N; int A[200000]; int main(){ scanf("%d",&N); rep(i,N) scanf("%d",&A[i]); ULL m=1; bool large=false; rep(i,N){ m*=A[i]; if(m>N*2) large=true; m%=M; } if(!large){ vector<int> V={0}; rep(i,N){ if(V.size()%2==1){ if(A[i]==1) V.back()++; else V.push_back(A[i]); } else{ if(A[i]==1) V.push_back(1); else V.back()*=A[i]; } } int ans=0; struct Node{ int factor,term; } dp[32]={}; int n=V.size()/2; int p=n-1; rep(i,1<<n){ int p=n-1; while(p>=0&&(1<<(n-1-p))&~i) p--; if(p!=-1) dp[p+1]={dp[p].factor*V[p*2+1],dp[p].term}; p++; for(; p<n; p++) dp[p+1]={V[p*2+1],dp[p].term+dp[p].factor+V[p*2]}; ans=max(ans,dp[n].factor+dp[n].term); } if(V.size()%2==1) ans+=V.back(); printf("%d\n",ans); } else{ printf("%llu\n",m); } return 0; }