結果

問題 No.1687 What the Heck?
コンテスト
ユーザー noya2
提出日時 2021-07-18 18:41:24
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 835 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,280 ms
コンパイル使用メモリ 335,384 KB
実行使用メモリ 15,132 KB
最終ジャッジ日時 2026-06-21 19:49:38
合計ジャッジ時間 7,736 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 RE * 1
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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