結果
| 問題 |
No.3129 Multiple of Twin Subarray
|
| コンテスト | |
| ユーザー |
ococonomy1
|
| 提出日時 | 2025-04-25 22:06:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 2,000 ms |
| コード長 | 2,985 bytes |
| コンパイル時間 | 2,437 ms |
| コンパイル使用メモリ | 199,768 KB |
| 実行使用メモリ | 9,472 KB |
| 最終ジャッジ日時 | 2025-04-25 22:06:49 |
| 合計ジャッジ時間 | 5,051 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define AMARI 998244353
//#define AMARI 1000000007
#define el '\n'
#define El '\n'
#define YESNO(x) ((x) ? "Yes" : "No")
#define YES YESNO(true)
#define NO YESNO(false)
#define REV_PRIORITY_QUEUE(tp) priority_queue<tp,vector<tp>,greater<tp>>
#define EXIT_ANS(x) {cout << (x) << '\n'; return;}
template <typename T> void inline SORT(vector<T> &v){sort(v.begin(),v.end()); return;}
template <typename T> void inline VEC_UNIQ(vector<T> &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); return;}
template <typename T> T inline MAX(vector<T> &v){return *max_element(v.begin(),v.end());}
template <typename T> T inline MIN(vector<T> &v){return *min_element(v.begin(),v.end());}
template <typename T> T inline SUM(vector<T> &v){T ans = 0; for(int i = 0; i < (int)v.size(); i++)ans += v[i]; return ans;}
void inline TEST(void){cerr << "TEST" << endl; return;}
vector<vector<int>> inline get_graph(int n,int m = -1,bool direct = false){
if(m == -1)m = n - 1;
vector<vector<int>> g(n);
while(m--){
int u,v;
cin >> u >> v;
u--; v--;
g[u].push_back(v);
if(!direct)g[v].push_back(u);
}
return g;
}
vector<ll> make_max(vector<ll> const& a){
int n = (int)a.size();
vector<ll> ans(n);
ll mn = 0LL;
ll temp = 0LL;
for(int i = 0; i < n; i++){
temp += a[i];
ans[i] = temp - mn;
if(i)ans[i] = max(ans[i],ans[i - 1]);
ans[i] = max(ans[i],a[i]);
mn = min(mn,temp);
}
return ans;
}
ll func(vector<ll> a){
vector<ll> temp = make_max(a);
reverse(a.begin(),a.end());
vector<ll> temp2 = make_max(a);
reverse(temp2.begin(),temp2.end());
ll ans = LLONG_MIN / 2LL;
int n = (int)a.size();
for(int i = 0; i < n - 1; i++){
ans = max(ans,temp[i] * temp2[i + 1]);
}
return ans;
}
#define MULTI_TEST_CASE false
void solve(void){
//問題を見たらまず「この問題設定から言えること」をいっぱい言う
//よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く
//複数の解法のアイデアを思いついた時は全部メモしておく
//g++ -D_GLIBCXX_DEBUG -Wall -O2 f.cpp -o o
int n;
cin >> n;
vector<ll> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
ll ans = func(a);
for(int i =0 ; i < n; i++){
a[i] *= -1;
}
ans = max(ans,func(a));
cout << ans << el;
return;
}
void calc(void){
return;
}
signed main(void){
cin.tie(nullptr);
ios::sync_with_stdio(false);
calc();
int t = 1;
if(MULTI_TEST_CASE)cin >> t;
while(t--){
solve();
}
return 0;
}
ococonomy1