結果

問題 No.862 XORでX
ユーザー 👑 emthrmemthrm
提出日時 2019-08-10 00:31:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 2,548 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 126,748 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 22:17:05
合計ジャッジ時間 3,971 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 7 ms
4,376 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 8 ms
4,376 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 8 ms
4,376 KB
testcase_25 AC 8 ms
4,380 KB
testcase_26 AC 8 ms
4,376 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 8 ms
4,376 KB
testcase_29 AC 8 ms
4,376 KB
testcase_30 AC 8 ms
4,380 KB
testcase_31 AC 8 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, x; cin >> n >> x;
  vector<int> ans;
  if (x == 1) {
    for (int i = 8; i + 3 <= 100005; i += 4) {
      if (n > 4) {
        ans.emplace_back(i);
        ans.emplace_back(i + 1);
        ans.emplace_back(i + 2);
        ans.emplace_back(i + 3);
        n -= 4;
      }
    }
    vector<int> puzzle{1, 2, 3, 4, 7};
    int comb = (1 << n) - 1;
    while (comb < (1 << 5)) {
      int tmp = 0;
      REP(i, 5) {
        if (comb >> i & 1) tmp ^= puzzle[i];
      }
      if (tmp == x) {
        REP(i, 5) {
          if (comb >> i & 1) ans.emplace_back(puzzle[i]);
        }
        break;
      }
      int x = comb & -comb, y = comb + x;
      comb = (((comb & ~y) / x) >> 1) | y;
    }
  } else {
    for (int i = 2; i + 3 <= 100005; i += 4) {
      if (i <= x && x <= i + 3) continue;
      if (n > 4) {
        ans.emplace_back(i);
        ans.emplace_back(i + 1);
        ans.emplace_back(i + 2);
        ans.emplace_back(i + 3);
        n -= 4;
      }
    }
    int a = x / 4;
    if (x % 4 == 0 || x % 4 == 1) --a;
    vector<int> puzzle{1};
    FOR(i, 2, 6) puzzle.emplace_back(4 * a + i);
    int comb = (1 << n) - 1;
    while (comb < (1 << 5)) {
      int tmp = 0;
      REP(i, 5) {
        if (comb >> i & 1) tmp ^= puzzle[i];
      }
      if (tmp == x) {
        REP(i, 5) {
          if (comb >> i & 1) ans.emplace_back(puzzle[i]);
        }
        break;
      }
      int x = comb & -comb, y = comb + x;
      comb = (((comb & ~y) / x) >> 1) | y;
    }
  }
  REP(i, ans.size()) cout << ans[i] << '\n';
  return 0;
}
0