結果

問題 No.470 Inverse S+T Problem
ユーザー nebukuro09nebukuro09
提出日時 2016-12-20 00:42:27
言語 D
(dmd 2.107.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,464 bytes
コンパイル時間 1,446 ms
コンパイル使用メモリ 145,476 KB
実行使用メモリ 15,908 KB
最終ジャッジ日時 2023-09-02 23:58:55
合計ジャッジ時間 7,486 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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;
        used[s12] = 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;

    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