結果

問題 No.1687 What the Heck?
ユーザー ktr216ktr216
提出日時 2021-09-24 22:05:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 167,052 KB
実行使用メモリ 4,860 KB
最終ジャッジ日時 2023-09-18 21:23:58
合計ジャッジ時間 2,934 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 20 ms
4,376 KB
testcase_08 AC 28 ms
4,380 KB
testcase_09 AC 20 ms
4,376 KB
testcase_10 AC 13 ms
4,380 KB
testcase_11 AC 15 ms
4,376 KB
testcase_12 AC 57 ms
4,620 KB
testcase_13 AC 57 ms
4,860 KB
testcase_14 AC 57 ms
4,628 KB
testcase_15 AC 57 ms
4,612 KB
testcase_16 AC 56 ms
4,612 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 57 ms
4,720 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;

typedef long long ll;

int main() {
    ll N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, 0, N) {
        cin >> P[i];
        Q[P[i] - 1] = i + 1;
    }
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    if (N == 2) {
        if (P[0] == 1) cout << 0 << endl;
        else cout << 1 << endl;
        return 0;
    }
    ll t = N * (N + 1) / 2, ans = 0;
    //cout << ans << endl;
    rep(i, 0, N) {
        ans = max(ans, t - 2 * Q[N - 1 - i]);
        t -= Q[N - 1 - i];
        //cout << i << " " << ans << endl;
    }
    cout << ans << endl;
}
0