結果

問題 No.3017 交互浴
ユーザー elphe
提出日時 2025-02-11 19:24:40
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 869 bytes
コンパイル時間 1,044 ms
コンパイル使用メモリ 90,632 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-02-11 19:24:49
合計ジャッジ時間 8,186 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdint>
#include <vector>
#include <stack>

using namespace std;

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int32_t N, i;
	cin >> N;
	vector<int32_t> H(N);
	for (i = 0; i != N; ++i) cin >> H[i];

	stack<int32_t> s;
	int32_t ans = 0, lower;
	for (i = 0; i != N; ++i)
	{
		lower = 0;
		if (i & 1)
			while (true)
			{
				if (H[i] < s.top())
				{
					ans -= H[i] - lower, s.push(H[i]);
					break;
				}
				ans -= s.top() - lower, s.pop();

				if (s.empty() || H[i] <= s.top())
					break;
				else
					lower = s.top(), s.pop();
			}
		else
			while (true)
			{
				if (s.empty() || H[i] < s.top())
				{
					ans += H[i] - lower, s.push(H[i]);
					break;
				}
				ans += s.top() - lower, s.pop();

				if (H[i] <= s.top()) break;
				else lower = s.top(), s.pop();
			}

		cout << ans << '\n';
	}

	return 0;
}
0