結果

問題 No.1687 What the Heck?
ユーザー noya2noya2
提出日時 2021-07-18 18:43:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 7,222 ms
コンパイル使用メモリ 310,864 KB
実行使用メモリ 6,364 KB
最終ジャッジ日時 2023-09-18 20:24:18
合計ジャッジ時間 8,831 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 20 ms
4,380 KB
testcase_08 AC 28 ms
4,860 KB
testcase_09 AC 19 ms
4,376 KB
testcase_10 AC 13 ms
4,380 KB
testcase_11 AC 15 ms
4,376 KB
testcase_12 AC 56 ms
6,296 KB
testcase_13 AC 56 ms
6,364 KB
testcase_14 AC 56 ms
6,340 KB
testcase_15 AC 57 ms
6,300 KB
testcase_16 AC 56 ms
6,324 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 56 ms
6,260 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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");
	inf.readEoln();
	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