Submission #66386401
Source Code Expand
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <array>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define req(i, a, b) for (ll i = (a); i < (b); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n'
#define debug2(x, y) cerr << __LINE__ << ' ' << #x << ':' << (x) << ',' << #y << ':' << (y) << '\n'
#define debug3(x, y, z) cerr << __LINE__ << ' ' << #x << ':' << (x) << ',' << #y << ':' << (y) << ',' << #z << ':' << (z) << '\n'
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
template<class T> using P = pair<T, T>;
template<class T> using pri_l = priority_queue<T>;
template<class T> using pri_s = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr int inf2 = 2000000010;
constexpr ll INF = 1000000000000000010;
constexpr ll INF4 = 4000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1,0 }; int dy[] = { 0,1,0,-1,1,-1,1,-1,0 };
ll mul(ll a, ll b) { return (b != 0 && a > INF / b ? INF : a * b); }
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T> void er(T a) { cout << a << '\n'; exit(0); }
template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream& operator >>(istream& s, vector<T>& v) { for (auto& e : v) s >> e; return s; }
template<class T> ostream& operator <<(ostream& s, const vector<T>& v) { for (auto& e : v) s << e << ' '; return s; }
template<class T, class U> ostream& operator << (ostream& s, const pair<T, U>& p) { s << p.first << ' ' << p.second; return s; }
struct fastio {
fastio() {
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
cerr << fixed << setprecision(20);
}
}fastio_;
namespace rdv {
random_device seed_gen;
mt19937_64 engine(seed_gen());
ll rnum(ll r) { return engine() % r; } // [0, r)
ll rnum(ll l, ll r) { return rnum(r - l) + l; } // [l, r)
ll rng(ll l, ll r) { return rnum(l, r + 1); } // [l, r]
double rng01() { return engine() * pow(2, -64); }
template<class T> void shuf(vector<T>& v) { shuffle(all(v), engine); }
void shuf(string& s) { shuffle(all(s), engine); }
}
using namespace rdv;
template<class T> vector<int> compress(vector<T> v) {
int n = v.size();
vector<T> tmp = v;
sort(tmp.begin(), tmp.end());
tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
vector<int> res(n);
for (int i = 0; i < n; i++) res[i] = lower_bound(tmp.begin(), tmp.end(), v[i]) - tmp.begin();
return res;
}
#include <atcoder/all>
using namespace atcoder;
constexpr ll mod = mod998;
using mint = static_modint<mod>;
istream& operator >>(istream& s, mint& m) { ll y; s >> y; m = y; return s; }
ostream& operator <<(ostream& s, mint& m) { return s << m.val(); }
ostream& operator <<(ostream& s, const vector<mint>& v) { for (auto& e : v) s << e.val() << ' '; return s; }
vector<mint> fac, inv, facinv;
void modcalc(int n) {
fac.resize(n); inv.resize(n); facinv.resize(n);
fac[0] = 1; fac[1] = 1; inv[1] = 1;
facinv[0] = 1; facinv[1] = 1;
for (ll i = 2; i < n; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = -inv[mod % i] * (mod / i);
facinv[i] = facinv[i - 1] * inv[i];
}
}
mint comb(ll n, ll k) {
if (n < 0 || k < 0 || n < k) return 0;
return fac[n] * facinv[k] * facinv[n - k];
}
mint perm(ll n, ll k) {
if (n < 0 || k < 0 || n < k) return 0;
return fac[n] * facinv[n - k];
}
mint hom(ll n, ll k) {
if (n < 0 || k < 0 || n == 0 && k > 0) return 0;
if (n == 0 && k == 0) return 1;
return fac[n + k - 1] * facinv[k] * facinv[n - 1];
}
int main() {
int TEST;
cin >> TEST;
while (TEST--) {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
cin >> a;
bool ok = false;
vector<int> ans;
if (k == 0) {
ans.push_back(1);
ans.push_back(1);
ok = true;
}
else {
rep(s, n - 1) {
vector<int> res;
vector<ll> b = a;
auto op = [&](int i) -> void {
ll y = b[i] ^ b[i + 1];
b[i] = y, b[i + 1] = y;
res.push_back(i + 1);
};
auto swp = [&](int i) -> void {
// [x, x, y] -> [y, x, x]
op(i + 1);
op(i);
op(i + 1);
};
auto swp_rev = [&](int i) -> void {
// [x, y, y] -> [y, y, x]
op(i);
op(i + 1);
op(i);
};
op(s);
// debug(b);
for (int i = s; i < n - 2; i++) swp(i);
auto make = [&](vector<ll> &w) -> vector<ll> {
vector<ll> res;
for (auto e : w) {
for (auto f : res) chmin(e, e ^ f);
if (e != 0) res.push_back(e);
}
return res;
};
vector<bool> u(n);
ll tmp = k;
rep(i, n) {
vector<ll> w;
for (int j = i + 1; j < n; j++) w.push_back(b[j]);
w = make(w);
ll tt = tmp;
for (auto e : w) chmin(tt, tt ^ e);
if (tt == 0) u[i] = false;
else {
u[i] = true;
tmp ^= b[i];
}
}
ll sum = 0;
rep(i, n) if (u[i]) sum ^= b[i];
if (sum != k) continue;
if (u[n - 2] && u[n - 1]) {
u[n - 2] = false;
u[n - 1] = false;
}
else if (!u[n - 2] && u[n - 1]) {
u[n - 2] = true;
u[n - 1] = false;
}
// debug(b);
int mx = -1;
for (int i = n - 1; i >= 0; i--) {
if (u[i]) {
mx = i;
break;
}
}
// rep(i, n) debug(u[i]);
assert(0 <= mx && mx < n - 1);
int cur = n - 2;
// debug2(cur, mx);
if (mx != n - 2) {
for (int i = cur - 1; i >= mx + 1; i--) swp_rev(i);
op(mx);
op(mx + 1);
cur = mx + 1;
u[mx] = false;
}
// debug(b);
int nxt = -1;
for (int i = cur - 1; i >= 0; i--) {
if (u[i]) {
nxt = i;
break;
}
}
// debug(b);
// debug2(cur, nxt);
while (nxt != -1) {
// debug2(cur, nxt);
while (cur > nxt + 1) {
swp_rev(cur - 1);
cur--;
}
op(nxt);
op(nxt + 1);
op(nxt);
op(nxt + 1);
swp_rev(cur - 1);
cur--;
// debug(b); debug(cur); debug(nxt);
nxt = -1;
for (int i = cur - 1; i >= 0; i--) {
if (u[i]) {
nxt = i;
break;
}
}
}
// debug(cur);
while (cur >= 1) {
swp_rev(cur - 1);
cur--;
}
// debug(b);
assert(b[0] == k);
ok = true;
ans = res;
break;
}
}
if (!ok) cout << "No\n";
else {
cout << "Yes\n";
int sz = ssize(ans);
assert(sz <= 10000);
cout << sz << '\n';
rep(i, sz) cout << ans[i] << " \n"[i == sz - 1];
}
}
}
Submission Info
Submission Time
2025-06-01 22:03:50+0900
Task
B - Adjacent Replace
User
cn449
Language
C++ 20 (gcc 12.2)
Score
800
Code Size
7555 Byte
Status
AC
Exec Time
65 ms
Memory
3620 KiB
Compile Error
Main.cpp: In function ‘mint hom(ll, ll)’:
Main.cpp:126:38: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
126 | if (n < 0 || k < 0 || n == 0 && k > 0) return 0;
| ~~~~~~~^~~~~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
800 / 800
Status
Set Name
Test Cases
Sample
00_sample_00.txt
All
00_sample_00.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
1 ms
3572 KiB
01_test_00.txt
AC
1 ms
3552 KiB
01_test_01.txt
AC
1 ms
3472 KiB
01_test_02.txt
AC
5 ms
3620 KiB
01_test_03.txt
AC
5 ms
3616 KiB
01_test_04.txt
AC
6 ms
3612 KiB
01_test_05.txt
AC
16 ms
3536 KiB
01_test_06.txt
AC
9 ms
3540 KiB
01_test_07.txt
AC
8 ms
3448 KiB
01_test_08.txt
AC
1 ms
3512 KiB
01_test_09.txt
AC
20 ms
3540 KiB
01_test_10.txt
AC
61 ms
3548 KiB
01_test_11.txt
AC
65 ms
3524 KiB
01_test_12.txt
AC
56 ms
3500 KiB
01_test_13.txt
AC
1 ms
3600 KiB
01_test_14.txt
AC
3 ms
3528 KiB
01_test_15.txt
AC
3 ms
3540 KiB
01_test_16.txt
AC
5 ms
3572 KiB
01_test_17.txt
AC
4 ms
3568 KiB
01_test_18.txt
AC
5 ms
3524 KiB
01_test_19.txt
AC
5 ms
3604 KiB
01_test_20.txt
AC
9 ms
3464 KiB
01_test_21.txt
AC
17 ms
3576 KiB
01_test_22.txt
AC
42 ms
3600 KiB
01_test_23.txt
AC
43 ms
3436 KiB
01_test_24.txt
AC
1 ms
3604 KiB
01_test_25.txt
AC
1 ms
3536 KiB
01_test_26.txt
AC
1 ms
3540 KiB
01_test_27.txt
AC
1 ms
3532 KiB
01_test_28.txt
AC
1 ms
3532 KiB
01_test_29.txt
AC
2 ms
3576 KiB
01_test_30.txt
AC
19 ms
3584 KiB
01_test_31.txt
AC
17 ms
3496 KiB
01_test_32.txt
AC
43 ms
3428 KiB