結果

問題 No.862 XORでX
ユーザー risujirohrisujiroh
提出日時 2019-08-09 23:18:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 2,202 bytes
コンパイル時間 1,627 ms
コンパイル使用メモリ 173,780 KB
実行使用メモリ 8,284 KB
最終ジャッジ日時 2023-09-26 22:02:03
合計ジャッジ時間 4,589 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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;
  }

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

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

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