結果

問題 No.3129 Multiple of Twin Subarray
ユーザー yel_ow
提出日時 2025-04-26 11:07:47
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 953 bytes
コンパイル時間 3,318 ms
コンパイル使用メモリ 277,464 KB
実行使用メモリ 12,576 KB
最終ジャッジ日時 2025-04-26 11:07:54
合計ジャッジ時間 7,116 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <monsterenergy>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int MAX = 1e9;
const int MIN = -1*1e9;
const ll MAXLL = 1e18;
const ll MINLL = -1*1e18;
int N;

ll Solve(vector<ll> A)
{
    vector<ll> L(N+2,MINLL),R(N+2,MINLL);
    L[0] = 0;
    for(int i = 1; i <= N; i++)
    {
        L[i] = max({L[i-1]+A[i],A[i]});
    }
    for(int i = 2; i <= N; i++) L[i] = max(L[i],L[i-1]);

    R[N+1] = 0;
    for(int i = N; i >= 1; i--)
    {
        R[i] = max({R[i+1]+A[i],A[i]});
    }
    for(int i = N-1; i >= 1; i--) R[i] = max(R[i],R[i+1]);

    ll Ans = MINLL;
    for(int i = 1; i < N; i++)
    {
        Ans = max(Ans,L[i]*R[i+1]);
    }
    return Ans;
}

int main()
{
    cin >> N;
    vector<ll> A(N+1),B(N+1);
    for(int i = 1; i <= N; i++) cin >> A[i], B[i] = -A[i];

    cout << max(Solve(A),Solve(B)) << endl;
    return 0;
}
0