結果

問題 No.474 色塗り2
ユーザー snukesnuke
提出日時 2016-12-22 17:45:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,123 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 82,036 KB
実行使用メモリ 126,300 KB
最終ジャッジ日時 2024-05-08 11:06:39
合計ジャッジ時間 1,626 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
110,720 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def ext_gcd(a, b):
    if b == 0:
        return [1, 0]
    else:
        y, x = ext_gcd(b, a % b)
        return [x, y - (a // b) * x]

def minv(n, m):
    return ext_gcd(n, m)[0]

mod = 1<<21

fact_factor2 = [0] * mod
fact_mod = [0] * mod
fact_mod_inv = [0] * mod

fact_mod[0] = 1
for i in range(1, mod):
    j = i
    f2 = 0
    while j % 2 == 0:
        f2 += 1
        j = j // 2
    fact_mod[i] = fact_mod[i-1] * j % mod
    fact_factor2[i] = fact_factor2[i-1] + f2

fact_mod_inv[-1] = minv(fact_mod[-1], mod)
for i in range(mod-1, 0, -1):
    j = i
    while j % 2 == 0:
        j = j // 2
    fact_mod[i-1] = fact_mod[i] * j % mod

def solve(A, B, C):
    if C % 2 == 0:
        return 0
    else:
        f2 = fact_factor2[C+B-1] - fact_factor2[B] - fact_factor2[C-1]
        val = fact_mod[C+B-1] * fact_mod_inv[B] % mod * fact_mod_inv[C-1] % mod
        val = ((C * val % mod) << min(32, f2)) % mod + A - 1
        if (val & A) == A:
            return 1
        else:
            return 0

testcase = int(input())
for _ in range(testcase):
    A, B, C = list(map(int, input().split()))
    print(solve(A, B, C))
0