結果

問題 No.1421 国勢調査 (Hard)
ユーザー SSRSSSRS
提出日時 2021-03-05 22:11:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,210 bytes
コンパイル時間 1,677 ms
コンパイル使用メモリ 171,832 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 09:44:38
合計ジャッジ時間 5,374 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
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 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 65 ms
6,944 KB
testcase_28 AC 67 ms
6,944 KB
testcase_29 AC 64 ms
6,944 KB
testcase_30 AC 64 ms
6,944 KB
testcase_31 AC 64 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> S(M, vector<int>(N + 1, 0));
  for (int i = 0; i < M; i++){
    int A;
    cin >> A;
    for (int j = 0; j < A; j++){
      int B;
      cin >> B;
      B--;
      S[i][B] = 1;
    }
    cin >> S[i][N];
  }
  int c = 0;
  vector<int> id;
  for (int i = 0; i < N; i++){
    int p = c;
    for (int j = c; j < M; j++){
      if (S[j][i] == 1){
        p = j;
      }
    }
    swap(S[c], S[p]);
    if (S[p][i] > 0){
      c++;
      for (int j = 0; j < M; j++){
        if (j != p && S[j][i] == 1){
          for (int k = 0; k <= N; k++){
            S[j][k] ^= S[p][k];
          }
        }
      }
      id.push_back(i);
    }
    if (c == M){
      break;
    }
  }
  int cnt = id.size();
  vector<int> X(N, 0);
  for (int i = 0; i < cnt; i++){
    X[id[i]] = S[i][N];
  }
  bool ok = true;
  for (int i = 0; i < M; i++){
    int s = 0;
    for (int j = 0; j < N; j++){
      if (S[i][j] == 1){
        s ^= X[j];
      }
    }
    if (s != S[i][N]){
      ok = false;
    }
  }
  if (!ok){
    cout << -1 << endl;
  } else {
    for (int i = 0; i < N; i++){
      cout << X[i] << endl;
    }
  }
}
0