結果
| 問題 |
No.505 カードの数式2
|
| コンテスト | |
| ユーザー |
lapi
|
| 提出日時 | 2019-04-06 11:35:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,269 bytes |
| コンパイル時間 | 821 ms |
| コンパイル使用メモリ | 103,832 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-14 07:32:52 |
| 合計ジャッジ時間 | 1,757 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
ll f(ll x, ll y, int ope) {
if (ope == 0) return x + y;
else if (ope == 1) return x - y;
else if (ope == 2) return x*y;
else return x / y;
}
int a[16];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
for (int i = 0; i < N; i++) cin >> a[i];
ll up = a[0];
ll bottom = a[0];
for (int i = 1; i < N; i++) {
ll tmpup = -LLINF;
ll tmpbottom = LLINF;
for (int j = 0; j < 3; j++) {
tmpup = max(tmpup, f(up, a[i], j));
tmpup = max(tmpup, f(bottom, a[i], j));
tmpbottom = min(tmpbottom, f(up, a[i], j));
tmpbottom = min(tmpbottom, f(bottom, a[i], j));
}
if (a[i] != 0) {
tmpup = max(tmpup, f(up, a[i], 3));
tmpup = max(tmpup, f(bottom, a[i], 3));
tmpbottom = min(tmpbottom, f(up, a[i], 3));
tmpbottom = min(tmpbottom, f(bottom, a[i], 3));
}
up = tmpup;
bottom = tmpbottom;
}
cout << up << endl;
return 0;
}
lapi