結果

問題 No.790 ちきんの括弧並べ
ユーザー ooaiu
提出日時 2025-02-12 19:04:01
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 779 bytes
コンパイル時間 3,532 ms
コンパイル使用メモリ 276,932 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-12 19:04:09
合計ジャッジ時間 7,423 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) (void(0))
#endif
void run_case();
int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int T = 1;
	// cin >> T;
	while (T--) run_case();
	return 0;
}
int N;
int ans;
void dfs(string s, int l = 0, int r = 0) {
	if(s.size() == 2 * N) {
		// cout << s << endl;
		int t = 0;
		bool f = true;
		for(char c: s) {
			if(c == '(') t++;
			else t--;
			if(t < 0) {
				f = false;
				break;
			}
		}
		f &= t == 0;
		ans += f;
		return;
	}
	if(l < N) {
		s += '(';
		dfs(s, l + 1, r);
		s.pop_back();
	}
	if(r < N) {
		s += ')';
		dfs(s, l, r + 1);
		s.pop_back();
	}
}
void run_case() {
	cin >> N;
	dfs("");
	cout << ans << endl;
}
0