結果
問題 |
No.505 カードの数式2
|
ユーザー |
![]() |
提出日時 | 2017-07-01 17:32:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 843 bytes |
コンパイル時間 | 857 ms |
コンパイル使用メモリ | 94,548 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-04 23:51:30 |
合計ジャッジ時間 | 1,844 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 WA * 5 |
ソースコード
#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; int a[N]; FOR(i,0,N) cin >> a[i]; int dp[N+1][2]; // 最大と最小のみ保存していく dp[1][0] = dp[1][1] = a[0]; FOR(i,1,N){ vector<int> 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; }