結果

問題 No.1687 What the Heck?
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-03 18:05:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 559 bytes
コンパイル時間 907 ms
コンパイル使用メモリ 107,540 KB
実行使用メモリ 4,636 KB
最終ジャッジ日時 2023-08-28 08:01:26
合計ジャッジ時間 3,056 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 21 ms
4,376 KB
testcase_08 AC 29 ms
4,376 KB
testcase_09 AC 20 ms
4,376 KB
testcase_10 AC 14 ms
4,380 KB
testcase_11 AC 14 ms
4,376 KB
testcase_12 AC 62 ms
4,564 KB
testcase_13 AC 63 ms
4,580 KB
testcase_14 AC 63 ms
4,580 KB
testcase_15 AC 64 ms
4,636 KB
testcase_16 AC 62 ms
4,600 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 63 ms
4,584 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

int main(){

    ll N, P, S, ans=0;
    cin >> N;
    S = N*(N+1)/2;
    vector<ll> Q(N+1);
    for (int i=1; i<=N; i++){
        cin >> P;
        Q[P] = i;
    }
    for (int i=N; i>=1; i--){
        ans = max(ans, S-Q[i] * 2);
        S -= Q[i];
    }

    cout << ans << endl;

    return 0;
}
0