結果

問題 No.1687 What the Heck?
ユーザー ktr216
提出日時 2021-09-24 22:04:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 675 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 168,504 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-05 10:37:36
合計ジャッジ時間 4,696 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 2 WA * 16
権限があれば一括ダウンロードができます

ソースコード

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