結果
| 問題 |
No.3129 Multiple of Twin Subarray
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-26 02:49:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 2,000 ms |
| コード長 | 1,323 bytes |
| コンパイル時間 | 4,378 ms |
| コンパイル使用メモリ | 256,512 KB |
| 実行使用メモリ | 26,752 KB |
| 最終ジャッジ日時 | 2025-04-26 02:50:00 |
| 合計ジャッジ時間 | 8,131 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#include <bits/stdc++.h>
#include <algorithm>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)
template <typename T> bool chmin(T& x, T y) {
return x > y ? (x = y, true) : false;
}
template <typename T> bool chmax(T& x, T y) {
return x < y ? (x = y, true) : false;
}
struct IOST {
IOST() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
}
} IOST;
void solve() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, 0, n) cin >> a[i];
vector dp(n + 1, vector<ll>(2));
dp[0] = {(ll)-1e18, (ll)1e18};
{
ll mx = 0;
ll mn = 0;
rep(i, 0, n) {
mx = max(a[i], mx + a[i]);
mn = min(a[i], mn + a[i]);
dp[i + 1] = dp[i];
chmax(dp[i + 1][0], mx);
chmin(dp[i + 1][1], mn);
}
}
vector rdp(n + 1, vector<ll>(2));
rdp[n] = {(ll)-1e18, (ll)1e18};
{
{
ll mx = 0;
ll mn = 0;
for (int i = n - 1; i >= 0; i--) {
mx = max(a[i], mx + a[i]);
mn = min(a[i], mn + a[i]);
rdp[i] = rdp[i + 1];
chmax(rdp[i][0], mx);
chmin(rdp[i][1], mn);
}
}
}
ll ans = -1e18;
rep(i, 1, n) {
chmax(ans, dp[i][0] * rdp[i][0]);
chmax(ans, dp[i][1] * rdp[i][1]);
}
cout << ans << "\n";
}
int main() {
int t = 1;
// cin >> t;
rep(i, 0, t) solve();
}