結果

問題 No.3129 Multiple of Twin Subarray
ユーザー tnakao0123
提出日時 2025-04-28 14:56:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,697 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 41,596 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-04-28 14:56:31
合計ジャッジ時間 4,464 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:33:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |   for (int i = 0; i < n; i++) scanf("%d", as + i);
      |                               ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3129.cc:  No.3129 Multiple of Twin Subarray - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int INF = (1U << 31) - 1;
const long long LINF = 1LL << 62;

/* typedef */

using ll = long long;

/* global variables */

int as[MAX_N];
int lxs[MAX_N + 1], rxs[MAX_N + 1], lns[MAX_N + 1], rns[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  lxs[0] = -INF;
  for (int i = 0, s = 0, mns = 0; i < n; i++) {
    s += as[i];
    lxs[i + 1] = max(lxs[i], s - mns);
    mns = min(mns, s);
  }
  //for (int i = 1; i <= n; i++) printf(" %d", lxs[i]); putchar('\n');

  rxs[n] = -INF;
  for (int i = n - 1, s = 0, mns = 0; i >= 0; i--) {
    s += as[i];
    rxs[i] = max(rxs[i + 1], s - mns);
    mns = min(mns, s);
  }
  //for (int i = 0; i < n; i++) printf(" %d", rxs[i]); putchar('\n');

  lns[0] = INF;
  for (int i = 0, s = 0, mxs = 0; i < n; i++) {
    s += as[i];
    lns[i + 1] = min(lns[i], s - mxs);
    mxs = max(mxs, s);
  }
  //for (int i = 1; i <= n; i++) printf(" %d", lns[i]); putchar('\n');

  rns[n] = INF;
  for (int i = n - 1, s = 0, mxs = 0; i >= 0; i--) {
    s += as[i];
    rns[i] = min(rns[i + 1], s - mxs);
    mxs = max(mxs, s);
  }
  //for (int i = 0; i < n; i++) printf(" %d", rns[i]); putchar('\n');

  ll maxp = -LINF;
  for (int i = 1; i < n; i++) {
    ll p0 = (ll)lxs[i] * rxs[i];
    ll p1 = (ll)lxs[i] * rns[i];
    ll p2 = (ll)lns[i] * rxs[i];
    ll p3 = (ll)lns[i] * rns[i];
    maxp = max(maxp, max(max(p0, p1), max(p2, p3)));
  }

  printf("%lld\n", maxp);
  
  return 0;
}
0