結果

問題 No.1687 What the Heck?
ユーザー icchipost
提出日時 2021-10-22 17:53:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 1,603 ms
コンパイル使用メモリ 167,696 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-22 21:29:12
合計ジャッジ時間 3,484 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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