結果

問題 No.1687 What the Heck?
ユーザー zezerozezero
提出日時 2021-09-24 22:09:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 639 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 107,048 KB
実行使用メモリ 13,004 KB
最終ジャッジ日時 2023-09-18 21:27:06
合計ジャッジ時間 3,567 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 59 ms
6,684 KB
testcase_08 AC 85 ms
8,196 KB
testcase_09 AC 56 ms
6,940 KB
testcase_10 AC 35 ms
5,540 KB
testcase_11 AC 39 ms
5,748 KB
testcase_12 AC 219 ms
13,004 KB
testcase_13 AC 219 ms
12,916 KB
testcase_14 AC 218 ms
12,728 KB
testcase_15 AC 207 ms
12,728 KB
testcase_16 AC 211 ms
12,568 KB
testcase_17 AC 11 ms
4,376 KB
testcase_18 AC 208 ms
12,724 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 = -1;
    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