結果

問題 No.1420 国勢調査 (Easy)
ユーザー outlineoutline
提出日時 2021-03-05 22:59:00
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 1,104 ms / 2,000 ms
コード長 1,899 bytes
コンパイル時間 3,564 ms
コンパイル使用メモリ 163,516 KB
実行使用メモリ 22,292 KB
最終ジャッジ日時 2024-04-16 10:59:02
合計ジャッジ時間 16,387 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 448 ms
12,988 KB
testcase_03 AC 454 ms
12,984 KB
testcase_04 AC 457 ms
12,988 KB
testcase_05 AC 458 ms
12,992 KB
testcase_06 AC 459 ms
12,984 KB
testcase_07 AC 134 ms
14,264 KB
testcase_08 AC 76 ms
14,148 KB
testcase_09 AC 48 ms
11,816 KB
testcase_10 AC 47 ms
12,072 KB
testcase_11 AC 47 ms
11,948 KB
testcase_12 AC 21 ms
8,416 KB
testcase_13 AC 231 ms
8,432 KB
testcase_14 AC 13 ms
8,016 KB
testcase_15 AC 230 ms
8,428 KB
testcase_16 AC 219 ms
8,556 KB
testcase_17 AC 230 ms
8,428 KB
testcase_18 AC 222 ms
8,428 KB
testcase_19 AC 229 ms
8,556 KB
testcase_20 AC 235 ms
8,428 KB
testcase_21 AC 221 ms
8,432 KB
testcase_22 AC 1,104 ms
17,936 KB
testcase_23 AC 1,091 ms
17,960 KB
testcase_24 AC 1,068 ms
17,912 KB
testcase_25 AC 1,092 ms
17,992 KB
testcase_26 AC 1,099 ms
17,964 KB
testcase_27 AC 73 ms
22,164 KB
testcase_28 AC 74 ms
22,036 KB
testcase_29 AC 77 ms
22,032 KB
testcase_30 AC 73 ms
22,292 KB
testcase_31 AC 72 ms
22,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M), Y(M);
    for(int i = 0; i < M; ++i){
        cin >> A[i] >> B[i] >> Y[i];
        --A[i], --B[i];
    }

    vector<int> X(N);
    for(int k = 0; k < 30; ++k){
        two_sat ts(N);
        for(int i = 0; i < M; ++i){
            if(Y[i] >> k & 1){
                ts.add_clause(A[i], false, B[i], false);
                ts.add_clause(A[i], true, B[i], true);
            }
            else{
                ts.add_clause(A[i], false, B[i], true);
                ts.add_clause(A[i], true, B[i], false);
            }
        }
        if(!ts.satisfiable()){
            cout << -1 << endl;
            return 0;
        }
        auto sat = ts.answer();
        for(int i = 0; i < N; ++i){
            if(!sat[i])  X[i] += 1 << k;
        }
    }

    for(int i = 0; i < N; ++i)  cout << X[i] << '\n';

    return 0;
}
0