結果

問題 No.470 Inverse S+T Problem
ユーザー 14番14番
提出日時 2016-12-23 05:41:39
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,159 bytes
コンパイル時間 2,321 ms
コンパイル使用メモリ 108,008 KB
実行使用メモリ 31,624 KB
最終ジャッジ日時 2023-08-24 01:24:34
合計ジャッジ時間 8,488 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
23,636 KB
testcase_01 AC 58 ms
23,404 KB
testcase_02 AC 60 ms
21,228 KB
testcase_03 AC 60 ms
23,400 KB
testcase_04 AC 57 ms
21,432 KB
testcase_05 AC 60 ms
21,392 KB
testcase_06 AC 72 ms
22,876 KB
testcase_07 AC 71 ms
22,976 KB
testcase_08 AC 71 ms
25,080 KB
testcase_09 AC 60 ms
19,368 KB
testcase_10 AC 60 ms
21,440 KB
testcase_11 AC 269 ms
25,420 KB
testcase_12 AC 60 ms
19,448 KB
testcase_13 AC 61 ms
21,356 KB
testcase_14 AC 62 ms
21,308 KB
testcase_15 AC 68 ms
23,468 KB
testcase_16 AC 60 ms
21,532 KB
testcase_17 AC 61 ms
21,520 KB
testcase_18 AC 60 ms
23,352 KB
testcase_19 AC 71 ms
23,576 KB
testcase_20 AC 58 ms
21,284 KB
testcase_21 AC 60 ms
21,240 KB
testcase_22 AC 60 ms
21,300 KB
testcase_23 AC 61 ms
23,376 KB
testcase_24 AC 59 ms
21,344 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;

public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        int inputCount = int.Parse(Reader.ReadLine());
        this.WordList = new string[inputCount];
        for(int i=0; i<inputCount; i++) {
            this.WordList[i] = Reader.ReadLine();
        }
        if(inputCount > ('z'-'a') + ('Z' - 'A') + 2) {
            Console.WriteLine("Impossible");
            return;
        }
        List<string> ans = this.GetAns(0, new Dictionary<string, int>());
        if(ans == null) {
            Console.WriteLine("Impossible");
        } else {
            ans.ForEach(a=>Console.WriteLine(a));
        }
    }

    private List<string> GetAns(int idx, Dictionary<string, int> dic) {
        string str1 = WordList[idx].Substring(0,1);
        string str2 = WordList[idx].Substring(1,2);
        if((!dic.ContainsKey(str1)) && (!dic.ContainsKey(str2))) {
            if(idx < this.WordList.Length - 1) {
                dic.Add(str1, idx);
                dic.Add(str2, idx);
                List<string> tmp = GetAns(idx+1, dic);
                dic.Remove(str1);
                dic.Remove(str2);
                if(tmp != null) {
                    tmp.Insert(0, str1 + " " + str2);
                    return tmp;
                }
            } else {
                return new string[] {str1 + " " + str2}.ToList();
            }
        }
        if(str1.Equals(this.WordList[idx].Substring(2))) {
            if(dic.ContainsKey(str1)) {
                return null;
            }
        }
        if(str2.Equals(this.WordList[idx].Substring(0,2))) {
            if(dic.ContainsKey(str2)) {
                return null;
            }
        }
        str1 = this.WordList[idx].Substring(0, 2);
        str2 = this.WordList[idx].Substring(2, 1);   
        if((!dic.ContainsKey(str1)) && (!dic.ContainsKey(str2))) {
            if(idx < this.WordList.Length - 1) {
                dic.Add(str1, idx);
                dic.Add(str2, idx);
                List<string> tmp = GetAns(idx+1, dic);
                dic.Remove(str1);
                dic.Remove(str2);
                if(tmp != null) {
                    tmp.Insert(0, str1 + " " + str2);
                    return tmp;
                }
            } else {
                return new string[] {str1 + " " + str2}.ToList();
            }
        }
        return null;
    }

    private string[] WordList;
    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"



";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0