結果

問題 No.1687 What the Heck?
ユーザー zezerozezero
提出日時 2021-09-24 22:12:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 638 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 106,140 KB
実行使用メモリ 12,784 KB
最終ジャッジ日時 2023-09-18 21:31:10
合計ジャッジ時間 3,481 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 56 ms
6,752 KB
testcase_08 AC 83 ms
8,060 KB
testcase_09 AC 55 ms
6,656 KB
testcase_10 AC 36 ms
5,536 KB
testcase_11 AC 38 ms
5,772 KB
testcase_12 AC 197 ms
12,728 KB
testcase_13 AC 209 ms
12,724 KB
testcase_14 AC 205 ms
12,740 KB
testcase_15 AC 211 ms
12,716 KB
testcase_16 AC 216 ms
12,576 KB
testcase_17 AC 11 ms
4,376 KB
testcase_18 AC 224 ms
12,784 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 = 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