結果
問題 |
No.790 ちきんの括弧並べ
|
ユーザー |
|
提出日時 | 2025-02-12 19:10:47 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 199 ms / 2,000 ms |
コード長 | 798 bytes |
コンパイル時間 | 3,402 ms |
コンパイル使用メモリ | 275,492 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-02-12 19:10:51 |
合計ジャッジ時間 | 4,274 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
#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 && r < l) { s += ')'; dfs(s, l, r + 1); s.pop_back(); } } void run_case() { cin >> N; dfs(""); cout << ans << endl; }