結果
| 問題 | No.3223 K-XOR Increasing Sequence |
| コンテスト | |
| ユーザー |
nauclhlt
|
| 提出日時 | 2025-07-06 17:56:30 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 4,594 bytes |
| 記録 | |
| コンパイル時間 | 949 ms |
| コンパイル使用メモリ | 203,964 KB |
| 最終ジャッジ日時 | 2026-07-13 01:37:52 |
| 合計ジャッジ時間 | 6,424 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/stl_algobase.h:76,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/algorithm:62,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bit: In instantiation of 'constexpr int std::__popcount(_Tp) [with _Tp = long long int]':
main.cpp:175:27: required from here
175 | if (__popcount(X) == 1)
| ~~~~~~~~~~^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bit:308:34: error: argument 1 in call to function '__builtin_popcountg' has signed type
308 | return __builtin_popcountg(__x);
| ^~~
ソースコード
#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 (Y == 0)
{
cout << "No" << endl;
return 0;
}
else if (X == 0 && K >= 2)
{
if (N >= K + 3)
{
vector<ll> A(N);
if (K % 2 == 0)
{
A[0] = 0;
A[1] = 1;
for (int i = 2; i < N - 1; i++)
{
A[i] = 3;
}
A[N - 1] = Y;
}
else if (K % 3 == 0)
{
A[0] = 0;
A[1] = 3;
vector<ll> cycle = {1, 3, 2};
for (int i = 2; i < N - 1; i++)
{
A[i] = cycle[(i - 2) % 3];
}
A[N - 1] = Y;
}
else if (K % 3 == 1)
{
A[0] = 0;
A[1] = 2;
for (int i= 2; i < N - 1; i++)
{
int pos = (i - 2) % K;
if (pos < 2)
{
A[i] = 2;
}
else if (pos >= K - 2)
{
A[i] = 3;
}
else
{
A[i] = ((pos - 2) % 3) + 1;
}
}
A[N - 1] = Y;
}
else if (K % 3 == 2)
{
A[0] = 0;
A[1] = 2;
for (int i = 2; i < N - 1; i++)
{
int pos = (i - 2) % K;
if (pos < K - 2)
{
A[i] = pos % 3 + 1;
}
else
{
A[i] = 3;
}
}
A[N - 1] = Y;
}
cout << "Yes" << endl;
print(A.begin(), A.end());
return 0;
}
else if (N == K + 1)
{
vector<ll> A(N);
A[N - 1] = Y;
cout << "Yes" << endl;
print(A.begin(), A.end());
return 0;
}
else if (N == K + 2)
{
if (Y == 1)
{
cout << "No" << endl;
return 0;
}
else
{
vector<ll> A(N);
A[N - 2] = 1;
A[N - 1] = Y;
cout << "Yes" << endl;
print(A.begin(), A.end());
return 0;
}
}
}
else 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());
return 0;
}
else
{
cout << "No" << endl;
return 0;
}
}
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());
return 0;
}
}
nauclhlt