結果

問題 No.1734 Decreasing Elements
ユーザー kotatsugame
提出日時 2021-11-05 22:43:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 260 ms / 3,000 ms
コード長 657 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 84,876 KB
実行使用メモリ 14,760 KB
最終ジャッジ日時 2024-11-06 13:43:58
合計ジャッジ時間 5,317 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
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