結果

問題 No.470 Inverse S+T Problem
コンテスト
ユーザー 梧桐
提出日時 2026-06-20 17:32:45
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,586 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 541 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2026-06-20 17:33:02
合計ジャッジ時間 4,651 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 6 TLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdio>
#include <set>

using namespace std;

const int N = 100010;

int n;
string s[N];

/**
 * 1.n>=53肯定无解,单个字母重复
 * 2.2_SAT???
 */

int main() {
    // freopen("st.in", "r", stdin);
    // freopen("st.out", "w", stdout);

    scanf("%d", &n);
    for (int i = 0; i < n; ++i) cin >> s[i];

    if (n >= 53) {
        puts("Impossible");
        return 0;
    } else {
        bool flag = false;
        set<string> ss;
        for (int i = 0; i < 1 << n; ++i) {
            ss.clear();
            bool ok = true;
            for (int j = 0; j < n; ++j) {
                string a, b;
                if (i >> j & 1) {
                    a = s[j].substr(0, 1);
                    b = s[j].substr(1, 2);
                } else {
                    a = s[j].substr(0, 2);
                    b = s[j].substr(2, 1);
                }
                if (ss.count(a) || ss.count(b)) {
                    ok = false;
                    break;
                }
                ss.insert(a);
                ss.insert(b);
            }
            if (ok) {
                for (int j = 0; j < n; ++j) {
                    if (i >> j & 1) {
                        cout << s[j][0] << ' ' << s[j][1] << s[j][2] << endl;
                    } else {
                        cout << s[j][0] << s[j][1] << ' ' << s[j][2] << endl;
                    }
                }
                flag = true;
                break;
            }
        }
        if (!flag) {
            puts("Impossible");
        }
    }
    
    return 0;
}
0