結果

問題 No.1687 What the Heck?
ユーザー Manuel1024
提出日時 2022-09-07 21:55:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 71,576 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-23 13:00:28
合計ジャッジ時間 2,968 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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