結果

問題 No.862 XORでX
ユーザー maspy
提出日時 2020-03-28 18:23:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 20,480 KB
最終ジャッジ日時 2025-01-02 11:59:20
合計ジャッジ時間 4,451 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def fill(A, N):
    N -= len(A)
    B = A[:]
    for i in range(2, 10 ** 5 + 4, 2):
        if not N:
            break
        if (i in A) or (i + 1 in A):
            continue
        N -= 2
        B.append(i)
        B.append(i + 1)
    return B


def solve(N, X):
    if X == 1:
        if N % 4 == 0:
            return fill([1, 3, 5, 6], N)
        elif N % 4 == 1:
            return fill([1], N)
        elif N % 4 == 2:
            return fill([2, 3], N)
        else:
            return fill([3, 5, 7], N)
    if N % 4 == 0:
        return fill([1, X], N)
    elif N % 4 == 1:
        return fill([X], N)
    elif N % 4 == 2:
        return fill([1, X ^ 1], N)
    else:
        return fill([X ^ 1], N)


N, X = map(int, read().split())
A = solve(N, X)
print('\n'.join(map(str, A)))
0