結果

問題 No.862 XORでX
ユーザー pekempeypekempey
提出日時 2019-08-09 22:38:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 1,621 ms
コンパイル使用メモリ 179,332 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-07-19 14:42:16
合計ジャッジ時間 4,071 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, X; cin >> N >> X;
  vector<int> p(7); rep(i, 7) p[i] = i + 1;
  set<int> h1, h2, h3, h4;
  h1.insert(X);
  do {
    set<int> s2 { p[0], X ^ p[0] };
    set<int> s3 { p[0], p[1], X ^ p[0] ^ p[1] };
    set<int> s4 { p[0], p[1], p[2], X ^ p[0] ^ p[1] ^ p[2] };
    if (!s2.count(0) && *s2.rbegin() <= 100005 && s2.size() == 2) h2 = s2;
    if (!s3.count(0) && *s3.rbegin() <= 100005 && s3.size() == 3) h3 = s3;
    if (!s4.count(0) && *s4.rbegin() <= 100005 && s4.size() == 4) h4 = s4;
  } while (next_permutation(p.begin(), p.end()));
  set<int> ans;
  if (N % 4 == 1) {
    ans = h1;
  } else if (N % 4 == 2) {
    ans = h2;
  } else if (N % 4 == 3) {
    ans = h3;
  } else {
    ans = h4;
  }
  for (int i = 8; i <= 100005 && ans.size() < N; i += 2) {
    if (!ans.count(i) && !ans.count(i ^ 1)) {
      ans.insert(i);
      ans.insert(i ^ 1);
    }
  }
  for (int x : ans) cout << x << '\n';
}
0