結果

問題 No.1687 What the Heck?
コンテスト
ユーザー zezero
提出日時 2021-09-24 22:12:12
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 638 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 811 ms
コンパイル使用メモリ 121,180 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2026-06-23 06:15:54
合計ジャッジ時間 3,042 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    if (n == 1){
        cout << 0 << endl;
        return 0;
    }
    map<int,int> mp;
    rep(i,n){
        ll x;
        cin >> x;
        mp[int(x)] = i+1; 
    }
    ll sum = n*(n+1)/2;
    for (int i = n;i >= 1;i--){
        ans = max(sum - 2*mp[i],ans);
        sum -= mp[i];
    }

    cout << ans << endl;

    return 0;
}
0