結果

問題 No.790 ちきんの括弧並べ
ユーザー 大橋佐和大橋佐和
提出日時 2022-05-06 19:21:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 978 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 86,840 KB
実行使用メモリ 77,012 KB
最終ジャッジ日時 2023-09-19 08:29:40
合計ジャッジ時間 3,583 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,244 KB
testcase_01 AC 74 ms
71,196 KB
testcase_02 AC 76 ms
71,368 KB
testcase_03 AC 83 ms
76,384 KB
testcase_04 AC 85 ms
76,416 KB
testcase_05 AC 86 ms
76,420 KB
testcase_06 AC 89 ms
76,364 KB
testcase_07 AC 97 ms
76,528 KB
testcase_08 AC 312 ms
76,960 KB
testcase_09 AC 978 ms
77,012 KB
testcase_10 AC 75 ms
71,224 KB
testcase_11 AC 73 ms
71,256 KB
testcase_12 AC 143 ms
76,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def popcnt3(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)
    c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)
    c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)
    c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)
    return c


n = int(input())

a = 0
for i in range(1 << 2 * n):
    if not i & 1:
        continue
    if i >> 2 * n & 1:
        continue
    if popcnt3(i) != n:
        continue
    s = 0
    for j in range(2 * n):
        if i >> j & 1:
            s += 1
        else:
            s -= 1
        if s < 0:
            break
    if s == 0:
        a += 1

print(a)
0