Submission #4608286


Source Code Expand

Copy
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#define MOD (1000000007l)

using namespace std;

long count_bit(long v) {
  if (v == 0) return 0;
  return count_bit(v >> 1) + (v & 1);
}

void solve(long from, long to, long N, long mask_position) {
  if (count_bit(mask_position) == N - 1) {
    cout << " " << to;
    return;
  }
  long i = 0;
  for (; i < N; i++) {
    long now = 1l << i;
    if ((mask_position & now) == 0 and (from & now) != (to & now)) {
      break;
    }
  }
  long next_mask_position = mask_position | i;
  long j = 0;
  for (; j < N; j++) {
    long now = 1l << j;
    if ((mask_position & now) == 0) {
      break;
    }
  }
  long via = from ^ (1l << j);
  long via_2 = via ^ (1l << i);
  solve(from, via, N, next_mask_position);
  cout << " " << via_2;
  solve(via_2, to, N, next_mask_position);
}

int main(void) {
  long N, A, B;
  cin >> N >> A >> B;

  if (count_bit(A) % 2 == count_bit(B) % 2) {
    cout << "NO" << endl;
    return 0;
  }

  cout << "YES" << endl;
  cout << A;
  solve(A, B, N, 0);
  cout << endl;

  return 0;
}

Submission Info

Submission Time
Task C - Differ by 1 Bit
User set0gut1
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1151 Byte
Status

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt, sample-02.txt
All 0 / 800 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 01-47.txt, 01-48.txt, 01-49.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-01.txt 1 ms 256 KB
01-02.txt
01-03.txt 1 ms 256 KB
01-04.txt 1 ms 256 KB
01-05.txt 1 ms 256 KB
01-06.txt
01-07.txt 1 ms 256 KB
01-08.txt
01-09.txt 1 ms 256 KB
01-10.txt
01-11.txt 1 ms 256 KB
01-12.txt
01-13.txt 1 ms 256 KB
01-14.txt
01-15.txt 1 ms 256 KB
01-16.txt
01-17.txt 1 ms 256 KB
01-18.txt
01-19.txt 1 ms 256 KB
01-20.txt
01-21.txt 1 ms 256 KB
01-22.txt
01-23.txt 1 ms 256 KB
01-24.txt
01-25.txt 1 ms 256 KB
01-26.txt
01-27.txt 1 ms 256 KB
01-28.txt
01-29.txt 1 ms 256 KB
01-30.txt
01-31.txt 1 ms 256 KB
01-32.txt
01-33.txt
01-34.txt
01-35.txt
01-36.txt
01-37.txt
01-38.txt
01-39.txt
01-40.txt
01-41.txt
01-42.txt
01-43.txt
01-44.txt
01-45.txt
01-46.txt
01-47.txt
01-48.txt
01-49.txt
sample-01.txt 1 ms 256 KB
sample-02.txt 1 ms 256 KB