結果

問題 No.1687 What the Heck?
ユーザー icchiposticchipost
提出日時 2021-10-22 17:53:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 168,720 KB
実行使用メモリ 4,872 KB
最終ジャッジ日時 2023-10-24 04:31:49
合計ジャッジ時間 4,643 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 22 ms
4,348 KB
testcase_08 AC 31 ms
4,348 KB
testcase_09 AC 22 ms
4,348 KB
testcase_10 AC 15 ms
4,348 KB
testcase_11 AC 16 ms
4,348 KB
testcase_12 AC 62 ms
4,872 KB
testcase_13 AC 62 ms
4,872 KB
testcase_14 AC 62 ms
4,872 KB
testcase_15 AC 63 ms
4,872 KB
testcase_16 AC 62 ms
4,872 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 63 ms
4,872 KB
testcase_19 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<int> s(n + 1);
  for (int i = 1; i <= n; i++) s[a[i]] = i;
  ll cur = (ll)n * (n + 1) / 2, ans = 0;
  for (int i = n; i >= 1; i--) {
    ans = max(ans, cur - s[i] * 2);
    cur -= s[i];
  }
  cout << ans << endl;
  return 0;
}
0