結果

問題 No.3129 Multiple of Twin Subarray
ユーザー Aeren
提出日時 2025-04-25 21:55:52
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,486 bytes
コンパイル時間 3,229 ms
コンパイル使用メモリ 277,804 KB
実行使用メモリ 10,392 KB
最終ジャッジ日時 2025-04-25 21:56:06
合計ジャッジ時間 5,450 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

// #include <bits/allocator.h> // Temp fix for gcc13 global pragma
// #pragma GCC target("avx2,bmi2,popcnt,lzcnt")
// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif
#ifdef LOCAL
	#include "Debug.h"
#else
	#define debug_endl() 42
	#define debug(...) 42
	#define debug2(...) 42
	#define debug_bin(...) 42
#endif



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	int n;
	cin >> n;
	vector<int> a(n);
	copy_n(istream_iterator<int>(cin), n, a.begin());
	const int64_t inf = numeric_limits<int64_t>::max() / 2;
	const int64_t minf = numeric_limits<int64_t>::min() / 2;
	vector<array<int64_t, 2>> pref(n + 1, {inf, minf}), suff(n + 1, {inf, minf});
	array<int64_t, 2> cur{inf, minf};
	for(auto i = 0; i < n; ++ i){
		pref[i + 1] = pref[i];
		cur[0] = min(cur[0], 0L) + a[i];
		cur[1] = max(cur[1], 0L) + a[i];
		pref[i + 1][0] = min(pref[i + 1][0], cur[0]);
		pref[i + 1][1] = max(pref[i + 1][1], cur[1]);
	}
	cur = {inf, minf};
	for(auto i = n - 1; i >= 0; -- i){
		suff[i] = suff[i + 1];
		cur[0] = min(cur[0], 0L) + a[i];
		cur[1] = max(cur[1], 0L) + a[i];
		suff[i][0] = min(suff[i][0], cur[0]);
		suff[i][1] = max(suff[i][1], cur[1]);
	}
	int64_t res = minf;
	for(auto i = 1; i < n; ++ i){
		for(auto x: pref[i]){
			for(auto y: suff[i]){
				res = max(res, x * y);
			}
		}
	}
	cout << res << "\n";
	return 0;
}

/*

*/
0