結果

問題 No.790 ちきんの括弧並べ
ユーザー tobusakanatobusakana
提出日時 2023-09-07 20:38:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 415 bytes
コンパイル時間 464 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 76,568 KB
最終ジャッジ日時 2023-09-07 20:38:21
合計ジャッジ時間 2,753 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,156 KB
testcase_01 AC 72 ms
71,328 KB
testcase_02 AC 68 ms
71,312 KB
testcase_03 AC 68 ms
71,452 KB
testcase_04 AC 76 ms
75,780 KB
testcase_05 AC 73 ms
75,752 KB
testcase_06 AC 74 ms
76,244 KB
testcase_07 AC 76 ms
75,812 KB
testcase_08 AC 89 ms
76,568 KB
testcase_09 AC 125 ms
76,556 KB
testcase_10 AC 63 ms
71,088 KB
testcase_11 AC 63 ms
71,108 KB
testcase_12 AC 77 ms
76,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# [開き括弧の個数, 今何番目]

N = int(input())
stack = []
stack.append([1, 1])
ans = 0
M = 2 * N
while stack:
    opened, cnt = stack.pop()
    if cnt == M:
        if opened == 0:
            ans += 1
        continue
    if opened - 1 >= 0:
        stack.append([opened - 1, cnt + 1])
    if M - (cnt + 1) >= opened + 1:
        stack.append([opened + 1, cnt + 1])

print(ans)            
        
    
0