Submission #33651579


Source Code Expand

#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <random>
#include <bitset>
using namespace std;

using ll = long long;
using ull = unsigned long long;

#define LOG(f...) fprintf(stderr, f)
// #define DBG(f...) printf("%3d: ", __LINE__), printf(f)
#define DBG(f...) void()
#define all(cont) begin(cont), end(cont)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

template <class T> void read(T &x) {
  char ch; x = 0;
  int f = 1;
  while (isspace(ch = getchar()));
  if (ch == '-') ch = getchar(), f = -1;
  do x = x * 10 + (ch - '0'); while (isdigit(ch = getchar()));
  x *= f;
}
template <class T, class ...A> void read(T &x, A&... args) { read(x); read(args...); }

const int N = 1005;
const int SIZ = 128;
using BS = bitset<SIZ>;

ull a[N], target[N];

mt19937 rng;
int R(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }

vector<int> ans;

void op(int r) {
  ans.push_back(r);
  for (int i = r; i > 1; --i)
    a[i] ^= a[i - 1];
}

ull b[64];
BS rep[64];

void clear() { memset(b, 0, sizeof(b)); memset(rep, 0, sizeof(rep)); }

void ins(ull x, int pos) {
  BS r; r[pos] = true;
  for (int i = 0; i < 60; ++i) {
    if ((~x >> i) & 1) continue;
    if (!b[i]) {
      b[i] = x;
      rep[i] = r;
      break;
    }
    x ^= b[i];
    r ^= rep[i];
  }
}

bool fail;
BS solve(ll x) {
  BS ans = 0; fail = false;
  for (int i = 0; i < 60; ++i) {
    if ((~x >> i) & 1) continue;
    if (!b[i]) { fail = true; break; }
    x ^= b[i]; ans ^= rep[i];
  }
  return ans;
}

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n;
  read(n);
  for (int i = 1; i <= n; ++i)
    read(a[i]);
  for (int i = 1; i <= n; ++i)
    read(target[i]);
  auto nosolu = [&]() { puts("No"); exit(0); };
  if (a[1] != target[1]) nosolu();
  for (int i = 1; i < n; ++i) {
    ins(a[i], 0);
    solve(target[i + 1] ^ a[i + 1]);
    if (fail) nosolu();
  }
  for (int i = 1; i <= 1300; ++i) {
    int j = R(2, n);
    op(j);
  }
  for (int i = 1; i <= n + 60; ++i)
    op(n);

  clear();
  for (int i = n; i > 1; --i) {
    DBG("work i = %d\n", i);
    BS s;
    while (true) {
      int j, li;
      ull val = a[i] ^ target[i];
      clear();
      for (j = i - 1, li = max(i - SIZ, 0); j > li; --j) {
        ins(a[j], i - j - 1);
        s = solve(val);
        if (!fail) break;
      }
      if (fail) {
        op(i);
        continue;
      }
      if (s[0]) {
        if (s.count() == 1) {
          assert(a[i - 1] == val);
          op(i);
          assert(a[i] == target[i]);
          break;
        }
        int cnt = 0;
        for (int k = j; k < i; ++k) {
          if (s[i - k - 1]) {
            ++cnt;
            if (cnt == 2) {
              op(k);
              break;
            }
          }
        }
        continue;
      }
      op(i);
    }
  }
  for (int i = 1; i <= n; ++i)
    assert(a[i] == target[i]);
  puts("Yes");
  printf("%d\n", (int)ans.size());
  for (int x : ans)
    printf("%d ", x);
  puts("");
  return 0;
}

Submission Info

Submission Time
Task E - Adjacent XOR
User RiverHamster
Language C++ (GCC 9.2.1)
Score 800
Code Size 3299 Byte
Status AC
Exec Time 153 ms
Memory 3312 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 58
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_yes_01.txt, 01_random_yes_02.txt, 01_random_yes_03.txt, 01_random_yes_04.txt, 01_random_yes_05.txt, 01_random_yes_06.txt, 01_random_yes_07.txt, 01_random_yes_08.txt, 01_random_yes_09.txt, 01_random_yes_10.txt, 01_random_yes_11.txt, 01_random_yes_12.txt, 01_random_yes_13.txt, 01_random_yes_14.txt, 01_random_yes_15.txt, 02_random_no_01.txt, 02_random_no_02.txt, 02_random_no_03.txt, 02_random_no_04.txt, 02_random_no_05.txt, 02_random_no_06.txt, 02_random_no_07.txt, 02_random_no_08.txt, 02_random_no_09.txt, 02_random_no_10.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt, 03_handmade_08.txt, 03_handmade_09.txt, 03_handmade_10.txt, 03_handmade_11.txt, 03_handmade_12.txt, 03_handmade_13.txt, 03_handmade_14.txt, 03_handmade_15.txt, 04_handmade2_01.txt, 04_handmade2_02.txt, 04_handmade2_03.txt, 04_handmade2_04.txt, 04_handmade2_05.txt, 04_handmade2_06.txt, 04_handmade2_07.txt, 04_handmade2_08.txt, 04_handmade2_09.txt, 04_handmade2_10.txt, 04_handmade2_11.txt, 04_handmade2_12.txt, 04_handmade2_13.txt, 04_handmade2_14.txt, 04_handmade2_15.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 10 ms 3000 KiB
00_sample_02.txt AC 2 ms 2940 KiB
00_sample_03.txt AC 4 ms 3168 KiB
01_random_yes_01.txt AC 3 ms 3076 KiB
01_random_yes_02.txt AC 144 ms 3124 KiB
01_random_yes_03.txt AC 140 ms 3180 KiB
01_random_yes_04.txt AC 135 ms 3292 KiB
01_random_yes_05.txt AC 46 ms 3260 KiB
01_random_yes_06.txt AC 121 ms 3188 KiB
01_random_yes_07.txt AC 96 ms 3188 KiB
01_random_yes_08.txt AC 151 ms 3272 KiB
01_random_yes_09.txt AC 149 ms 3312 KiB
01_random_yes_10.txt AC 150 ms 3204 KiB
01_random_yes_11.txt AC 150 ms 3196 KiB
01_random_yes_12.txt AC 150 ms 3176 KiB
01_random_yes_13.txt AC 149 ms 3276 KiB
01_random_yes_14.txt AC 148 ms 3308 KiB
01_random_yes_15.txt AC 149 ms 3292 KiB
02_random_no_01.txt AC 7 ms 2976 KiB
02_random_no_02.txt AC 2 ms 2940 KiB
02_random_no_03.txt AC 2 ms 3104 KiB
02_random_no_04.txt AC 2 ms 3092 KiB
02_random_no_05.txt AC 2 ms 2940 KiB
02_random_no_06.txt AC 2 ms 3060 KiB
02_random_no_07.txt AC 2 ms 3104 KiB
02_random_no_08.txt AC 2 ms 2940 KiB
02_random_no_09.txt AC 2 ms 3060 KiB
02_random_no_10.txt AC 2 ms 2936 KiB
03_handmade_01.txt AC 153 ms 3292 KiB
03_handmade_02.txt AC 149 ms 3300 KiB
03_handmade_03.txt AC 149 ms 3132 KiB
03_handmade_04.txt AC 152 ms 3296 KiB
03_handmade_05.txt AC 148 ms 3136 KiB
03_handmade_06.txt AC 152 ms 3120 KiB
03_handmade_07.txt AC 147 ms 3280 KiB
03_handmade_08.txt AC 149 ms 3176 KiB
03_handmade_09.txt AC 149 ms 3292 KiB
03_handmade_10.txt AC 148 ms 3180 KiB
03_handmade_11.txt AC 149 ms 3288 KiB
03_handmade_12.txt AC 151 ms 3132 KiB
03_handmade_13.txt AC 150 ms 3196 KiB
03_handmade_14.txt AC 150 ms 3136 KiB
03_handmade_15.txt AC 149 ms 3200 KiB
04_handmade2_01.txt AC 11 ms 3132 KiB
04_handmade2_02.txt AC 7 ms 3212 KiB
04_handmade2_03.txt AC 13 ms 3136 KiB
04_handmade2_04.txt AC 8 ms 3120 KiB
04_handmade2_05.txt AC 14 ms 3180 KiB
04_handmade2_06.txt AC 13 ms 3252 KiB
04_handmade2_07.txt AC 12 ms 3280 KiB
04_handmade2_08.txt AC 14 ms 3260 KiB
04_handmade2_09.txt AC 15 ms 3276 KiB
04_handmade2_10.txt AC 16 ms 3188 KiB
04_handmade2_11.txt AC 18 ms 3292 KiB
04_handmade2_12.txt AC 16 ms 3180 KiB
04_handmade2_13.txt AC 18 ms 3304 KiB
04_handmade2_14.txt AC 19 ms 3176 KiB
04_handmade2_15.txt AC 24 ms 3192 KiB