結果

問題 No.862 XORでX
ユーザー risujirohrisujiroh
提出日時 2019-08-09 22:53:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,641 bytes
コンパイル時間 1,792 ms
コンパイル使用メモリ 168,972 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-26 21:18:19
合計ジャッジ時間 7,691 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, x; cin >> n >> x;
  if (n == 2) {
    if (x == 1) {
      cout << 2 << '\n';
      cout << 3 << '\n';
    } else {
      cout << 1 << '\n';
      cout << (x ^ 1) << '\n';
    }
    return 0;
  }

  V<> res;
  auto add = [&](int l, int r) -> void {
    for (int i = l; i < r; ++i) {
      res.push_back(i);
    }
  };

  assert(n % 4 <= 1);
  if (n % 4 == 0) {
    if (x < 4) {
      res.push_back(16 | x);
      res.push_back(20);
      res.push_back(24);
      res.push_back(28);
    } else {
      add(1, 4);
      int m = n / 4 - 1;
      for (int i = 4; m; i += 4, --m) {
        if (i <= x and x < i + 4) continue;
        add(i, i + 4);
      }
      res.push_back(x);
    }
  } else if (n % 4 == 1) {
    int m = n / 4;
    for (int i = 4; m; i += 4, --m) {
      if (i <= x and x < i + 4) continue;
      add(i, i + 4);
    }
    res.push_back(x);
  } else if (n % 4 == 2) {
    for (int i = x / 4 * 4; i < x / 4 * 4 + 4; ++i) if (i != x) {
      res.push_back(i);
    }
    add(1, 4);
    int m = n / 4;
    for (int i = 4; m; i += 4, --m) {
      if (i <= x and x < i + 4) continue;
      add(i, i + 4);
    }
  } else {
    for (int i = x / 4 * 4; i < x / 4 * 4 + 4; ++i) if (i != x) {
      res.push_back(i);
    }
    int m = n / 4;
    for (int i = 4; m; i += 4, --m) {
      if (i <= x and x < i + 4) continue;
      add(i, i + 4);
    }
  }

  for (int e : res) {
    cout << e << '\n';
  }
}
0