結果

問題 No.3142 Balancing with O=>X Flip
ユーザー elphe
提出日時 2025-05-17 11:25:12
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 1,176 ms
コンパイル使用メモリ 83,788 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-17 11:25:14
合計ジャッジ時間 2,305 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

static inline constexpr const char* solve(const uint32_t N, const string& S) noexcept
{
	uint32_t level = 0;
	for (uint32_t i = 0; i != N; ++i)
		switch (S[i])
		{
		case '(':
			++level;
			break;

		case ')':
			if (level == 0)
				return "No";
			--level;
			break;
		}

	if (level == 0)
		return "Yes";
	else
		return "No";
}

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

	uint32_t N;
	string S;
	cin >> N;
	S.reserve(N), cin >> S;

	cout << solve(N, S) << '\n';
	return 0;
}
0