結果

問題 No.470 Inverse S+T Problem
ユーザー nebukuro09nebukuro09
提出日時 2016-12-20 00:39:49
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,516 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 147,508 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-02 23:56:43
合計ジャッジ時間 3,463 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.ascii;

int N;
int[] ans;
string[] U;
bool[string] used;

bool dfs(int p) {
    if (p > N - 1)
        return true;

    string s0 = U[p][0].to!string;
    string s12 = U[p][1..3].to!string;
    string s01 = U[p][0..2].to!string;
    string s2 = U[p][2].to!string;
    if (!used[s0] && !used[s12]) {
        used[s0] = true;
        used[s12] = true;
        ans[p] = 0;
        if (dfs(p+1))
            return true;
        used[s0] = false;
    }
    if (!used[s01] && !used[s2]) {
        used[s01] = true;
        used[s2] = true;
        ans[p] = 1;
        if (dfs(p+1))
            return true;
        used[s01] = false;
        used[s2] = false;
    }
    return false;
}

void main() {
    N = readln.chomp.to!int;
    if (N > 52 + 52*52) {
        writeln("Impossible");
        return;
    }

    ans = new int[](N);
    U = new string[](N);
    foreach (i; 0..N)
        U[i] = readln.chomp;

    foreach (c1; letters) {
        used[c1.to!string] = false;
        foreach (c2; letters)
            used[c1.to!string ~ c2.to!string] = false;
    }

    if (dfs(0)) {
        foreach (i; 0..N) {
            if (ans[i] == 0)
                writeln(U[i][0], " ", U[i][1..3]);
            else
                writeln(U[i][0..2], " ", U[i][2]);
        }
    }
    else
        writeln("Impossible");

}
0