結果

問題 No.1687 What the Heck?
ユーザー Manuel1024Manuel1024
提出日時 2022-09-07 21:55:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 71,444 KB
実行使用メモリ 4,632 KB
最終ジャッジ日時 2023-08-15 07:07:24
合計ジャッジ時間 3,007 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 17 ms
4,380 KB
testcase_08 AC 25 ms
4,384 KB
testcase_09 AC 18 ms
4,388 KB
testcase_10 AC 12 ms
4,380 KB
testcase_11 AC 13 ms
4,384 KB
testcase_12 AC 51 ms
4,560 KB
testcase_13 AC 49 ms
4,600 KB
testcase_14 AC 51 ms
4,632 KB
testcase_15 AC 53 ms
4,616 KB
testcase_16 AC 50 ms
4,568 KB
testcase_17 AC 5 ms
4,384 KB
testcase_18 AC 50 ms
4,604 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n; cin >> n;
    vector<int> p(n);
    for(auto &it: p){
        cin >> it;
        it--;
    }

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