結果
問題 |
No.505 カードの数式2
|
ユーザー |
|
提出日時 | 2020-05-31 00:56:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 581 bytes |
コンパイル時間 | 2,425 ms |
コンパイル使用メモリ | 190,024 KB |
最終ジャッジ日時 | 2025-01-10 19:45:06 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 WA * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:35:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:36:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | rep(i,n) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; const long long INF=1LL<<61; int n,a[16]; char op[15]; lint dfs(int i){ if(i==n-1){ lint res=a[0]; rep(j,n-1){ if(op[j]=='+') res+=a[j+1]; if(op[j]=='-') res-=a[j+1]; if(op[j]=='*') res*=a[j+1]; } return res; } lint res=-INF; op[i]='+'; res=max(res,dfs(i+1)); op[i]='-'; res=max(res,dfs(i+1)); op[i]='*'; res=max(res,dfs(i+1)); return res; } int main(){ scanf("%d",&n); rep(i,n) scanf("%d",&a[i]); printf("%lld\n",dfs(0)); return 0; }