結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 58 ms
21,360 KB
testcase_02 AC 59 ms
21,392 KB
testcase_03 AC 60 ms
21,388 KB
testcase_04 AC 56 ms
21,356 KB
testcase_05 AC 58 ms
21,284 KB
testcase_06 AC 70 ms
25,028 KB
testcase_07 AC 70 ms
23,132 KB
testcase_08 AC 68 ms
22,924 KB
testcase_09 AC 58 ms
21,308 KB
testcase_10 AC 60 ms
21,424 KB
testcase_11 AC 267 ms
25,520 KB
testcase_12 AC 60 ms
23,396 KB
testcase_13 AC 60 ms
21,292 KB
testcase_14 WA -
testcase_15 AC 64 ms
21,372 KB
testcase_16 AC 59 ms
21,312 KB
testcase_17 AC 61 ms
23,336 KB
testcase_18 AC 60 ms
21,644 KB
testcase_19 AC 72 ms
23,452 KB
testcase_20 AC 60 ms
21,296 KB
testcase_21 AC 59 ms
21,368 KB
testcase_22 AC 59 ms
19,388 KB
testcase_23 AC 59 ms
23,404 KB
testcase_24 AC 59 ms
23,464 KB
testcase_25 AC 58 ms
21,480 KB
testcase_26 AC 58 ms
21,444 KB
testcase_27 AC 58 ms
23,296 KB
testcase_28 AC 54 ms
20,704 KB
testcase_29 AC 54 ms
20,804 KB
testcase_30 AC 54 ms
20,756 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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)) || str2.Equals(this.WordList[idx].Substring(0,2))) {
            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