結果

問題 No.1734 Decreasing Elements
ユーザー kotatsugamekotatsugame
提出日時 2021-11-05 22:43:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 274 ms / 3,000 ms
コード長 657 bytes
コンパイル時間 828 ms
コンパイル使用メモリ 84,000 KB
実行使用メモリ 14,756 KB
最終ジャッジ日時 2024-04-24 06:35:38
合計ジャッジ時間 5,414 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 85 ms
14,312 KB
testcase_08 AC 86 ms
14,308 KB
testcase_09 AC 83 ms
14,496 KB
testcase_10 AC 83 ms
14,756 KB
testcase_11 AC 139 ms
14,640 KB
testcase_12 AC 92 ms
10,400 KB
testcase_13 AC 147 ms
13,568 KB
testcase_14 AC 258 ms
14,652 KB
testcase_15 AC 199 ms
14,624 KB
testcase_16 AC 274 ms
14,460 KB
testcase_17 AC 273 ms
14,420 KB
testcase_18 AC 271 ms
14,460 KB
testcase_19 AC 171 ms
14,156 KB
testcase_20 AC 169 ms
14,152 KB
testcase_21 AC 166 ms
12,364 KB
testcase_22 AC 179 ms
13,900 KB
testcase_23 AC 176 ms
14,160 KB
testcase_24 AC 187 ms
14,288 KB
testcase_25 AC 201 ms
14,572 KB
testcase_26 AC 199 ms
14,476 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<set>
#include<queue>
#include<vector>
using namespace std;
int N;
main()
{
	cin>>N;
	set<int>S;
	S.insert(0);
	S.insert(2e5+1);
	priority_queue<pair<int,int> >P;
	P.push(make_pair(2e5+1,0));
	int ans=0;
	vector<pair<int,int> >upd;
	for(int i=0;i<N;i++)
	{
		int A;cin>>A;
		auto it=S.upper_bound(A);
		it--;
		if(*it==A)continue;
		int d=A-*it;
		{
			upd.clear();
			while(P.top().first>d)
			{
				pair<int,int>p=P.top();
				P.pop();
				P.push(make_pair(d,p.second));
				upd.push_back(make_pair(p.first-d,p.second+d));
				S.insert(p.second+d);
			}
			for(pair<int,int>&p:upd)P.push(p);
		}
		ans++;
	}
	cout<<ans<<endl;
}
0