結果
問題 | No.1421 国勢調査 (Hard) |
ユーザー | e869120 |
提出日時 | 2021-03-05 22:07:24 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 903 ms / 2,000 ms |
コード長 | 2,077 bytes |
コンパイル時間 | 1,039 ms |
コンパイル使用メモリ | 93,272 KB |
実行使用メモリ | 7,956 KB |
最終ジャッジ日時 | 2024-04-16 09:36:55 |
合計ジャッジ時間 | 11,287 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
7,628 KB |
testcase_01 | AC | 2 ms
7,756 KB |
testcase_02 | AC | 3 ms
7,756 KB |
testcase_03 | AC | 4 ms
7,752 KB |
testcase_04 | AC | 3 ms
7,756 KB |
testcase_05 | AC | 3 ms
7,628 KB |
testcase_06 | AC | 4 ms
7,884 KB |
testcase_07 | AC | 3 ms
7,632 KB |
testcase_08 | AC | 3 ms
7,628 KB |
testcase_09 | AC | 3 ms
7,624 KB |
testcase_10 | AC | 3 ms
7,752 KB |
testcase_11 | AC | 4 ms
7,760 KB |
testcase_12 | AC | 3 ms
7,624 KB |
testcase_13 | AC | 3 ms
7,628 KB |
testcase_14 | AC | 3 ms
7,628 KB |
testcase_15 | AC | 3 ms
7,760 KB |
testcase_16 | AC | 3 ms
7,628 KB |
testcase_17 | AC | 3 ms
7,756 KB |
testcase_18 | AC | 3 ms
7,632 KB |
testcase_19 | AC | 3 ms
7,756 KB |
testcase_20 | AC | 3 ms
7,628 KB |
testcase_21 | AC | 3 ms
7,756 KB |
testcase_22 | AC | 873 ms
7,756 KB |
testcase_23 | AC | 874 ms
7,888 KB |
testcase_24 | AC | 868 ms
7,956 KB |
testcase_25 | AC | 875 ms
7,884 KB |
testcase_26 | AC | 868 ms
7,880 KB |
testcase_27 | AC | 903 ms
7,884 KB |
testcase_28 | AC | 877 ms
7,756 KB |
testcase_29 | AC | 875 ms
7,888 KB |
testcase_30 | AC | 866 ms
7,756 KB |
testcase_31 | AC | 864 ms
7,880 KB |
ソースコード
#include <iostream> #include <set> #include <map> #include <cmath> #include <queue> #include <vector> #include <string> #include <algorithm> #include <functional> using namespace std; long long N, M; long long A[1 << 18], Y[1 << 18]; long long Answer[1 << 18]; bool flag = false; long long solve(vector<pair<long long, int>> A) { // 掃き出し法 sort(A.begin(), A.end()); for (int i = 49; i >= 0; i--) { for (int j = 0; j < A.size(); j++) { if ((A[j].first & (1LL << i)) != 0) { for (int k = j + 1; k < A.size(); k++) { if ((A[k].first & (1LL << i)) == 0) continue; A[k].first ^= A[j].first; A[k].second ^= A[j].second; } break; } } sort(A.begin(), A.end()); } if (A[0].first == 0 && A[0].second == 1) return -1; for (int i = 0; i < (int)A.size() - 1; i++) { if (A[i].first == A[i + 1].first && A[i].second != A[i + 1].second) return -1; } // ビットの計算 long long bit[55]; for (int i = 0; i < 55; i++) bit[i] = 0; for (int i = 0; i < (int)A.size(); i++) { int maximum = 0, s = A[i].second; for (int j = 0; j < 55; j++) { if ((A[i].first & (1LL << j)) != 0LL) maximum = j; } for (int j = 0; j < maximum; j++) { if ((A[i].first & (1LL << j)) != 0LL) s ^= bit[j]; } bit[maximum] = s; } long long ret = 0; for (int i = 0; i < 55; i++) { if (bit[i] == 1) ret += (1LL << i); } return ret; } int main() { // Step 1. 入力 cin >> N >> M; for (int i = 1; i <= M; i++) { long long s, t; cin >> s; for (int j = 0; j < s; j++) { cin >> t; A[i] += (1LL << (t - 1)); } cin >> Y[i]; } // Step #2. ビットごとに計算 for (int i = 0; i < 30; i++) { vector<pair<long long, int>> vec; for (int j = 1; j <= M; j++) { vec.push_back(make_pair(A[j], (Y[j] / (1LL << i)) % 2LL)); } long long Z = solve(vec); if (Z == -1) flag = true; for (int j = 0; j < N; j++) Answer[j] += (1LL << i) * ((Z / (1LL << j)) % 2LL); } // Step #3. 出力 if (flag == true) { cout << "-1" << endl; } else { for (int i = 0; i < N; i++) cout << Answer[i] << endl; } return 0; }