Submission #70103908


Source Code Expand

from sys import stdin
def input():
    return stdin.readline().rstrip("\n")
def ok(c, x, n):
    return n and (n ^ c) % n == x


def solve2(c: int, x: int):
    if ok(c, x, c ^ x):
        return c ^ x
    # msb
    cm = c.bit_length() - 1
    c2 = 1 << cm
    if x < c2:
        # ?
        assert False
        return "??"
    if x < 2 * c2:
        if x > c:
            return -1
        n = 2 * c2 + (c - x) // 2
        if (n ^ c) % n != x:
            n = -1
        return n
    if x >> cm & 1:
        return -1
    return c ^ x

def solve():
    c, x = map(lambda s_: int(s_), input().split())
    print(solve2(c, x))
case_t = 1
case_t = int(input())
for _ in [None] * case_t:
    solve()


Submission Info

Submission Time
Task C - Mod of XOR
User wasd314
Language Python (PyPy 3.10-v7.3.12)
Score 700
Code Size 738 Byte
Status AC
Exec Time 135 ms
Memory 85812 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 1
AC × 22
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 53 ms 76384 KiB
01_handmade_00.txt AC 125 ms 85620 KiB
01_handmade_01.txt AC 118 ms 85216 KiB
01_handmade_02.txt AC 110 ms 85344 KiB
01_handmade_03.txt AC 129 ms 85612 KiB
01_handmade_04.txt AC 117 ms 84756 KiB
01_handmade_05.txt AC 117 ms 85600 KiB
02_random_00.txt AC 135 ms 85812 KiB
02_random_01.txt AC 131 ms 85548 KiB
02_random_02.txt AC 121 ms 85016 KiB
02_random_03.txt AC 120 ms 85008 KiB
02_random_04.txt AC 122 ms 85072 KiB
02_random_05.txt AC 126 ms 84884 KiB
02_random_06.txt AC 124 ms 84920 KiB
02_random_07.txt AC 124 ms 85144 KiB
02_random_08.txt AC 113 ms 84996 KiB
02_random_09.txt AC 113 ms 85068 KiB
02_random_10.txt AC 113 ms 84992 KiB
02_random_11.txt AC 121 ms 84760 KiB
02_random_12.txt AC 121 ms 85168 KiB
02_random_13.txt AC 120 ms 84876 KiB
02_random_14.txt AC 113 ms 84620 KiB