結果

問題 No.790 ちきんの括弧並べ
ユーザー a
提出日時 2019-04-27 12:06:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 408 ms / 2,000 ms
コード長 488 bytes
コンパイル時間 1,571 ms
コンパイル使用メモリ 165,576 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-27 14:04:23
合計ジャッジ時間 2,581 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < (1<<(n*2)); i++)
	{
		if (__builtin_popcount(i) != n) continue;
		int cnt = 0, ok = 1;
		for (int j = 0; j < 2*n; j++)
		{
			if (i >> j & 1)
			{
				cnt++;
			}
			else
			{
				if  (cnt == 0)
				{
					ok = 0;
					break;
				}
				cnt--;
			}
		}
		ans += ok;
	}
	cout << ans << endl;

}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}
0