結果

問題 No.5001 排他的論理和でランニング
ユーザー pekempeypekempey
提出日時 2018-03-17 00:08:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,670 bytes
コンパイル時間 495 ms
実行使用メモリ 62,732 KB
スコア 0
最終ジャッジ日時 2020-03-12 19:43:35
ジャッジサーバーID
(参考情報)
judge6 /
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <set>

using namespace std;

const int N = 1e5;

int n, m;
int a[N];
set<int> used[N];

void merge(set<int> &a, set<int> &b) {
  for (int x : b) {
    if (a.count(x)) {
      a.erase(x);
    } else {
      a.insert(x);
    }
  }
}

void swap_row(int i, int j) {
  swap(a[i], a[j]);
  swap(used[i], used[j]);
}

// i -> j
void add_row(int i, int j) {
  a[j] ^= a[i];
  merge(used[j], used[i]);
}

int gauss() {
  int r = 0;
  for (int j = 20; j >= 0; j--) {
    int p = -1;
    for (int i = r; i < n; i++) {
      if (a[i] >> j & 1) {
        p = i;
        break;
      }
    }
    if (p == -1) continue;
    swap_row(r, p);
    for (int i = r + 1; i < n; i++) {
      if (a[i] >> j & 1) {
        add_row(r, i);
      }
    }
    r++;
  }
  return r;
}

void answer(set<int> a) {
  bool fst = false;
  for (int x : a) {
    if (fst) {
      cout << ' ';
    }
    cout << x + 1;
    fst = true;
  }
  cout << endl;
  exit(0);
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    used[i].insert(i);
  }
  int r = gauss();

  set<int> res;
  int curr = 0;
  for (int i = 0; i < r; i++) {
    merge(res, used[i]);
    if ((curr ^ a[i]) > curr && res.size() <= m) {
      curr ^= a[i];
    } else {
      merge(res, used[i]);
    }
    if (res.size() == m) break;
  }
  cerr << curr << endl;
  if (res.size() == m) {
    answer(res);
  }
  cerr << res.size() << endl;
  for (int i = r; i < n; i++) {
    merge(res, used[i]);
    if (res.size() == m) {
      answer(res);
    }
    if (res.size() > m) {
      merge(res, used[i]);
    }
  }
}
0