結果

問題 No.1421 国勢調査 (Hard)
ユーザー tnakao0123tnakao0123
提出日時 2021-03-14 17:53:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,743 bytes
コンパイル時間 734 ms
コンパイル使用メモリ 94,992 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-24 00:53:47
合計ジャッジ時間 3,782 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1421.cc:  No.1421 国勢調査 (Hard) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;
const int MAX_M = 10000;

/* typedef */

typedef long long ll;

/* global variables */

ll bs[MAX_M];
int ys[MAX_M];

/* subroutines */

bool elimination(int n, int m) { // n <= m
  for (int i = 0; i < n; i++) {
    ll bi = 1LL << i;
    if ((bs[i] & bi) == 0) {
      int j = i + 1;
      for (; j < m && (bs[j] & bi) == 0; j++);
      if (j < m) swap(bs[i], bs[j]), swap(ys[i], ys[j]);
    }
    if ((bs[i] & bi) == 0) continue;

    for (int j = i + 1; j < m; j++)
      if ((bs[j] & bi) != 0)
	bs[j] ^= bs[i], ys[j] ^= ys[i];
  }

  for (int i = n - 1; i >= 0; i--) {
    ll bi = 1LL << i;
    if ((bs[i] & bi) == 0 && ys[i] != 0) return false;
    for (int j = i - 1; j >= 0; j--)
      if ((bs[j] & bi) != 0)
	bs[j] ^= bi, ys[j] ^= ys[i];
  }

  for (int j = 0; j < m; j++)
    if (bs[j] == 0 && ys[j] != 0) return false;

  return true;
}

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  ll nbits = 1LL << n;

  for (int i = 0; i < m; i++) {
    int ai;
    scanf("%d", &ai);
    for (int j = 0; j < ai; j++) {
      int bj;
      scanf("%d", &bj);
      bj--;
      bs[i] |= (1LL << bj);
    }
    scanf("%d", ys + i);
  }

  bool f = elimination(min(n, m), m);
  if (f)
    for (int i = 0; i < n; i++) printf("%d\n", ys[i]);
  else
    puts("-1");
  return 0;
}
0