結果

問題 No.2036 Max Middle
ユーザー publfl2publfl2
提出日時 2022-08-12 21:54:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 542 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 51,176 KB
実行使用メモリ 12,752 KB
最終ジャッジ日時 2023-10-24 09:46:56
合計ジャッジ時間 4,217 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <set>

int x[200010];
std::set< std::pair<int,int> > S;
int main()
{
	int ans = 0;
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	for(int i=2;i<=a-1;i++) S.insert(std::make_pair(x[i],i));
	while(!S.empty())
	{
		std::set< std::pair<int,int> > ::iterator it = S.end();
		it--;
		int ind = (it->second);
		S.erase(it);
		if(x[ind-1]<x[ind] && x[ind]>x[ind+1])
		{
			ans++;
			x[ind] = (x[ind-1]<x[ind+1]?x[ind-1]:x[ind+1])-1;
			S.insert(std::make_pair(x[ind],ind));
		}
	}
	printf("%d",ans);
}
0