結果

問題 No.1298 OR XOR
ユーザー FromBooskaFromBooska
提出日時 2023-10-01 21:16:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 71,660 KB
最終ジャッジ日時 2023-10-01 21:17:01
合計ジャッジ時間 2,922 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,512 KB
testcase_01 AC 71 ms
71,436 KB
testcase_02 AC 74 ms
71,624 KB
testcase_03 AC 72 ms
71,452 KB
testcase_04 AC 76 ms
71,120 KB
testcase_05 AC 72 ms
71,364 KB
testcase_06 AC 74 ms
71,660 KB
testcase_07 AC 72 ms
71,260 KB
testcase_08 AC 72 ms
71,324 KB
testcase_09 AC 73 ms
71,420 KB
testcase_10 AC 72 ms
71,120 KB
testcase_11 AC 74 ms
71,436 KB
testcase_12 AC 72 ms
71,368 KB
testcase_13 AC 74 ms
71,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ビット演算だからビット桁ごとに独立に考える
# Nのビット桁が1のときに、A, B, Cの2数に割り振っていく
# Nのビット桁1が1個しかないと、割り振られなかったところが0になってしまうので存在しない
# Nのビット桁1が2個以上あれば、最初はABに割り振り、あとはACに割り振ればいいだろう

N = int(input())
if bin(N).count('1') <= 1:
    print(-1, -1, -1)
else:
    A, B, C = 0, 0, 0
    first = False
    for d in range(31):
        if N>>d&1 == 1:
            if first == False:
                A += 1<<d
                B += 1<<d
                first = True
            elif first == True:
                A += 1<<d
                C += 1<<d
    #print(bin(A)[2:], bin(B)[2:], bin(C)[2:])
    #print(A|B == B|C == C|A == N, A^B^C==0)    
    print(A, B, C)
0