結果
問題 |
No.505 カードの数式2
|
ユーザー |
![]() |
提出日時 | 2025-06-19 19:57:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 758 bytes |
コンパイル時間 | 1,618 ms |
コンパイル使用メモリ | 162,196 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-19 19:57:30 |
合計ジャッジ時間 | 3,023 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
# include <bits/stdc++.h> # define int long long # define FILE(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout); using namespace std; int n, x; int a[2]; int b[2]; signed main() { //FILE("operations"); cin >> n >> x; a[0] = a[1] = x; for (int i = 1; i < n; i ++) { cin >> x; b[0] = -1e18, b[1] = 1e18; b[0] = max({b[0], a[0] + x, a[0] - x, a[0] * x, a[1] + x, a[1] - x, a[1] * x}); b[1] = min({b[1], a[0] + x, a[0] - x, a[0] * x, a[1] + x, a[1] - x, a[1] * x}); if (x) { b[0] = max({b[0], a[0] / x, a[1] / x}); b[1] = min({b[1], a[0] / x, a[1] / x}); } a[0] = b[0]; a[1] = b[1]; } cout << max(a[0], a[1]); return 0; }