結果
| 問題 |
No.3129 Multiple of Twin Subarray
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-25 22:11:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 931 bytes |
| コンパイル時間 | 2,053 ms |
| コンパイル使用メモリ | 197,924 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2025-04-25 22:11:24 |
| 合計ジャッジ時間 | 4,564 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
void solve() {
ll n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
if (n == 2) {
cout << a[0] * a[1] << '\n';
return;
}
ll ans = 0;
rep(t, 2) {
vector<ll> suml(n + 1, 0), sumr(n + 1, 0);
vector<ll> L(n + 1, 0), R(n + 1, 0);
rep(i, n) {
suml[i + 1] = max(suml[i] + a[i], 0ll);
L[i + 1] = max(L[i], suml[i + 1]);
}
rep(k, n) {
ll i = n - k;
sumr[i - 1] = max(sumr[i] + a[i - 1], 0ll);
R[i - 1] = max(R[i], sumr[i - 1]);
}
ll res = 0;
rep(i, n) if (i > 0) res = max(res, L[i] * R[i]);
ans = max(ans, res);
rep(i, n) a[i] = -a[i];
}
cout << ans << '\n';
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
int T = 1;
for (int t = 0; t < T; t++) {
solve();
}
return 0;
}