結果

問題 No.3017 交互浴
ユーザー kotatsugame
提出日時 2025-01-25 12:42:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 541 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 65,664 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-25 22:17:29
合計ジャッジ時間 7,901 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
struct dat{
	int l,r,c;
};
int N;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N;
	vector<dat>S;
	int sum=0;
	for(int i=0;i<N;i++)
	{
		int H;cin>>H;
		while(!S.empty()&&S.back().l<H)
		{
			dat t=S.back();
			S.pop_back();
			if(t.c==0)sum-=t.r-t.l;
			if(t.r>H)
			{
				t.l=H;
				if(t.c==0)sum+=t.r-t.l;
				S.push_back(t);
			}
		}
		dat t;
		t.r=H;
		t.l=0;
		t.c=i%2;
		S.push_back(t);
		if(t.c==0)sum+=t.r-t.l;
		cout<<sum<<"\n";
	}
}
0