結果

問題 No.1687 What the Heck?
ユーザー noya2noya2
提出日時 2021-07-18 18:42:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 838 bytes
コンパイル時間 7,279 ms
コンパイル使用メモリ 310,772 KB
実行使用メモリ 6,808 KB
最終ジャッジ日時 2023-09-18 20:24:35
合計ジャッジ時間 8,352 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "testlib.h"
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair<ll,ll>;

int main(){
	registerValidation();
	ll n = inf.readInt(1,200000,"n");
	vector<pll> ar(n);
	for (int i = 0; i < n; i++){
	    ll c = inf.readInt(1,n,"c");
	    ar[i] = pll(-c,ll(i+1));
	    if (i == n-1) inf.readEoln();
	    else inf.readSpace();
	}
	sort(ar.begin(),ar.end());
	if (n == 1){
	    assert(ar[0].first == -1);
	    cout << 0 << endl;
	    inf.readEof();
	    return 0;
	}
	ll f = n * (n + 1) / 2;
	ll ima = 2 * ar[0].second;
	ll mi = ima;
	for (int i = 0; i < n-1; i++){
	    ima = ima - ar[i].second + 2 * ar[i+1].second;
	    if (i == n-2) ima -= ar[i+1].second;
	    mi = min(mi,ima);
	}
	for (int i = 0; i < n; i++){
	    assert(n+ar[i].first == i);
	}
	cout << f - mi << endl;
	inf.readEof();
	return 0;
}
0