結果

問題 No.3223 K-XOR Increasing Sequence
ユーザー Nauclhlt🪷
提出日時 2025-07-01 18:24:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,872 bytes
コンパイル時間 3,334 ms
コンパイル使用メモリ 196,620 KB
実行使用メモリ 16,200 KB
最終ジャッジ日時 2025-07-06 17:58:29
合計ジャッジ時間 20,394 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

template <class _ForwardIterator>
void print(_ForwardIterator first, _ForwardIterator last)
{
    bool f = true;
    for (auto it = first; it != last; ++it)
    {
        if (!f)
        {
            cout << " ";
        }
        cout << *it;
        f = false;
    }

    cout << endl;
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;
    ll X, Y;
    cin >> X >> Y;

    if (K == 1)
    {
        vector<ll> A(N);
        if (Y - X >= N - 1)
        {
            for (int i = 0; i < N; i++)
            {
                A[i] = X + i;
            }
            A[N - 1] = Y;
            cout << "Yes" << endl;
            print(A.begin(), A.end());
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        vector<int> A(N);
        vector<int> B(K);
        if (K % 2 == 0)
        {
            for (int i = 0; i < K; i++)
            {
                B[i] = X;
            }
        }
        else
        {
            for (int i = 0; i < K - 3; i++)
            {
                B[i] = X;
            }
            
            if (__popcount(X) == 1)
            {
                int p = 0;
                while ((X & (1L << p)) != 0) p++;
                B[K - 3] = X;
                B[K - 2] = X | (1L << p);
                B[K - 1] = 1L << p;
            }
            else
            {
                int p = 0;
                while ((X & (1L << p)) == 0) p++;
                B[K - 3] = X;
                B[K - 2] = X ^ (1 << p);
                B[K - 1] = 1L << p;
            }
        }

        for (int i = 0; i < N; i++)
        {
            A[i] = B[i % K];
        }
        A[N - 1] = Y;

        cout << "Yes" << endl;
        print(A.begin(), A.end());
    }
}
0