結果

問題 No.470 Inverse S+T Problem
ユーザー parukiparuki
提出日時 2016-12-20 01:28:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,051 bytes
コンパイル時間 1,747 ms
コンパイル使用メモリ 178,940 KB
実行使用メモリ 6,828 KB
最終ジャッジ日時 2023-08-24 01:09:04
合計ジャッジ時間 12,302 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,508 KB
testcase_01 AC 4 ms
6,516 KB
testcase_02 AC 4 ms
6,744 KB
testcase_03 AC 6 ms
6,516 KB
testcase_04 AC 4 ms
6,516 KB
testcase_05 AC 4 ms
6,548 KB
testcase_06 AC 9 ms
6,508 KB
testcase_07 AC 9 ms
6,504 KB
testcase_08 AC 9 ms
6,520 KB
testcase_09 AC 8 ms
6,700 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 4 ms
6,512 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 691 ms
6,512 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 648 ms
6,520 KB
testcase_20 AC 4 ms
6,548 KB
testcase_21 AC 4 ms
6,520 KB
testcase_22 AC 4 ms
6,524 KB
testcase_23 AC 4 ms
6,596 KB
testcase_24 AC 794 ms
6,564 KB
testcase_25 AC 730 ms
6,572 KB
testcase_26 AC 949 ms
6,552 KB
testcase_27 AC 1,147 ms
6,808 KB
testcase_28 AC 5 ms
6,504 KB
testcase_29 AC 4 ms
6,544 KB
testcase_30 AC 5 ms
6,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
const string ALPHA="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int N;
string U[100001];
map<string, int> ms;
set<string> us;
int def[52];
string x[52], y[52];

void ng() {
    cout << "Impossible" << endl;
    exit(0);
}

int cnt = 0;

void f(int cu) {
    if(cnt++ == 3000000) {
        ng();
    }
    if(cu == 52) {
        if(sz(us) == 2 * N) {
            rep(i, N)cout << x[i] << ' ' << y[i] << endl;
            exit(0);
        } else {
            return;
        }
    }
    
    int non = 1;
    char c = ALPHA[cu];
    rep(i, N) if(!def[i]){
        string &u = U[i];
        def[i] = 1;
        if(u[0] == c) {
            non = 0;
            x[i] = u.substr(0, 1);
            y[i] = u.substr(1, 2);
            if(us.count(y[i]) + us.count(x[i]) == 0) {
                us.insert(x[i]);
                us.insert(y[i]);
                f(cu + 1);
                us.erase(x[i]);
                us.erase(y[i]);
            }
        }
        if(u[2] == c) {
            non = 0;
            x[i] = u.substr(0, 2);
            y[i] = u.substr(2, 1);
            if(us.count(x[i]) + us.count(y[i]) == 0) {
                us.insert(x[i]);
                us.insert(y[i]);
                f(cu + 1);
                us.erase(x[i]);
                us.erase(y[i]);
            }
        }
        def[i] = 0;
    }
    f(cu + 1);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    rep(i, N)cin >> U[i];

    if(N > 52) {
        ng();
    }

    f(0);
    ng();
}
0