結果
問題 |
No.505 カードの数式2
|
ユーザー |
![]() |
提出日時 | 2017-07-01 17:33:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 840 bytes |
コンパイル時間 | 905 ms |
コンパイル使用メモリ | 95,116 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-14 07:27:55 |
合計ジャッジ時間 | 1,857 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <cmath> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <stdlib.h> #include <stdio.h> #include <bitset> using namespace std; #define FOR(I,A,B) for(int I = (A); I < (B); ++I) typedef long long ll; int main(){ int N; cin >> N; ll a[N]; FOR(i,0,N) cin >> a[i]; ll dp[N+1][2]; // 最大と最小のみ保存していく dp[1][0] = dp[1][1] = a[0]; FOR(i,1,N){ vector<ll> v; FOR(j,0,2){ if(a[i] != 0) v.push_back(dp[i][j]/a[i]); v.push_back(dp[i][j]+a[i]); v.push_back(dp[i][j]-a[i]); v.push_back(dp[i][j]*a[i]); } sort(v.begin(), v.end()); dp[i+1][0] = v[0]; dp[i+1][1] = v[v.size()-1]; } cout << dp[N][1] << endl; return 0; }