結果

問題 No.3223 K-XOR Increasing Sequence
ユーザー HoyHoyCharhang
提出日時 2025-08-01 23:15:08
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 2,092 bytes
コンパイル時間 3,097 ms
コンパイル使用メモリ 279,668 KB
実行使用メモリ 10,952 KB
最終ジャッジ日時 2025-08-01 23:15:29
合計ジャッジ時間 17,872 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 70
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define eb emplace_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<typename T> using pq = priority_queue<T,vector<T>,greater<T>>;
using P = pair<int,int>;
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  if (y == 0) {
    cout << "No" << endl;
    return 0;
  }
  if (k == 1) {
    if (x+n-1 <= y) {
      cout << "Yes" << endl;
      rep(i,0,n-1) {
        cout << x+i << " ";
      }
      cout << y << endl;
    } else {
      cout << "No" << endl;
    }
    return 0;
  }
  if (x > 0) {
    vector<int> v(k, x);
    if (k % 2 == 1) {
      int z = (x == 1 ? 2 : 1);
      v[1] = x^z, v[2] = z;
    }
    vector<int> ans(n);
    rep(i,0,n-1) {
      ans[i] = v[i%k];
    }
    ans[n-1] = y;
    cout << "Yes" << endl;
    rep(i,0,n) {
      cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
  }
  if (n-k == 1) {
    cout << "Yes" << endl;
    rep(i,0,n-1) {
      cout << 0 << " ";
    }
    cout << y << endl;
    return 0;
  }
  if (y == 1 && n-k == 2) {
    cout << "No" << endl;
    return 0;
  }
  if (y == 2 && n-k == 2 && n%2 == 1) {
    cout << "Yes" << endl;
    rep(i,0,n-2) {
      cout << 0 << " ";
    }
    cout << "1 2" << endl;
    return 0;
  }
  vector<int> v(k);
  if (k % 2 == 0) {
    v.assign(k, 2);
    v[0] = v[1] = 3;
  } else {
    v.assign(k, 1);
    v[0] = 2, v[1] = 3;
  }
  vector<int> ans(n);
  rep(i,0,n-1) {
    ans[i] = v[i%k];
  }
  ans[0] = 0;
  ans[1] = (k%2 == 0 ? 2 : 1);
  ans[n-1] = y;
  cout << "Yes" << endl;
  rep(i,0,n) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
0