結果

問題 No.470 Inverse S+T Problem
ユーザー karinohitokarinohito
提出日時 2022-05-21 01:36:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,112 bytes
コンパイル時間 5,048 ms
コンパイル使用メモリ 268,348 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 01:46:00
合計ジャッジ時間 6,713 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)


bool chmax(ll& p, ll q) {
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

bool chmin(ll& p, ll q) {
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll PM(ll P, ll Q) {
    if (Q == 0)return P * 10;
    ll k = 1;
    ll V = Q;
    while (V > 0) {
        V /= 10;
        k *= 10;
    }
    return P * k + Q;
}


int main() {
    
    ll N;
    cin >> N;
    if (N > 26) {
        cout << "Impossible" << endl;
        return 0;
    }
    vector<string> S(N);
    rep(i, N)cin >> S[i];

    two_sat ts(N);
    rep(i, N)rep(j, i) {
        if (S[i].substr(0, 1) == S[j].substr(0, 1)) {
            ts.add_clause(i, 1, j, 1);
        }
        if (S[i].substr(0, 1) == S[j].substr(2, 1)) {
            ts.add_clause(i, 1, j, 0);
        }
        if (S[i].substr(2, 1) == S[j].substr(0, 1)) {
            ts.add_clause(i, 0, j, 1);
        }
        if (S[i].substr(2, 1) == S[j].substr(2, 1)) {
            ts.add_clause(i,0, j, 0);
        }

        if (S[i].substr(1, 2) == S[j].substr(1, 2)) {
            ts.add_clause(i, 1, j, 1);
        }
        if (S[i].substr(1, 2) == S[j].substr(0, 2)) {
            ts.add_clause(i, 1, j, 0);
        }
        if (S[i].substr(0, 2) == S[j].substr(1, 2)) {
            ts.add_clause(i, 0, j, 1);
        }
        if (S[i].substr(0, 2) == S[j].substr(0, 2)) {
            ts.add_clause(i, 0, j, 0);
        }
    }

    bool C = ts.satisfiable();
    if(!C)cout<< "Impossible" << endl;
    else {
        auto v = ts.answer();
        rep(i, N) {
            if (v[i]) {
                cout << S[i].substr(0, 2) << " " << S[i].substr(2, 1) << endl;
            }
            else {
                cout << S[i].substr(0, 1) << " " << S[i].substr(1,2) << endl;
            }
        }
    }



}
0