結果

問題 No.470 Inverse S+T Problem
ユーザー kuuso1kuuso1
提出日時 2016-12-20 01:21:52
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,954 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 106,128 KB
実行使用メモリ 33,684 KB
最終ジャッジ日時 2023-08-24 01:07:25
合計ジャッジ時間 9,232 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
27,808 KB
testcase_01 AC 80 ms
25,480 KB
testcase_02 AC 81 ms
23,464 KB
testcase_03 AC 82 ms
23,496 KB
testcase_04 AC 61 ms
24,712 KB
testcase_05 AC 83 ms
23,448 KB
testcase_06 AC 71 ms
24,740 KB
testcase_07 AC 71 ms
26,668 KB
testcase_08 AC 72 ms
24,708 KB
testcase_09 AC 82 ms
25,488 KB
testcase_10 AC 82 ms
23,412 KB
testcase_11 AC 469 ms
29,676 KB
testcase_12 AC 80 ms
25,428 KB
testcase_13 AC 84 ms
23,528 KB
testcase_14 AC 83 ms
25,484 KB
testcase_15 AC 80 ms
23,428 KB
testcase_16 AC 81 ms
23,500 KB
testcase_17 AC 87 ms
23,428 KB
testcase_18 AC 82 ms
23,380 KB
testcase_19 AC 87 ms
23,444 KB
testcase_20 AC 83 ms
23,492 KB
testcase_21 AC 86 ms
21,512 KB
testcase_22 AC 85 ms
25,496 KB
testcase_23 AC 83 ms
23,428 KB
testcase_24 AC 82 ms
23,464 KB
testcase_25 AC 82 ms
25,416 KB
testcase_26 TLE -
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.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		if(N > 52){
			Console.WriteLine("Impossible");
			return;
		}
		
		String[] S0 = new String[N];
		for(int i=0;i<N;i++)S0[i] = S[i];
		
		int[] ord = Enumerable.Range(0,N).ToArray();
		Array.Sort(S,ord);
		
		h = new HashSet<String>();
		found = false;
		route = new int[N];
		dfs(0);
		
		if(!found){
			Console.WriteLine("Impossible");
			return;
		}
		
		Array.Sort(ord,ans);
		for(int i=0;i<N;i++){
			Console.WriteLine("{0} {1}",S0[i].Substring(0,ans[i]),S0[i].Substring(ans[i]));
		}
		
		
		
	}
	
	bool found;
	int[] route;
	int[] ans;
	HashSet<String> h;
	void dfs(int now){
		if(found) return;
		if(now == N){
			found = true;
			ans = new int[N];
			for(int i=0;i<N;i++) ans[i] = route[i];
			return;
		}
		for(int j=1;j<=2;j++){
			var s0 = S[now].Substring(0,j);
			var s1 = S[now].Substring(j);
			if(!h.Contains(s0) && !h.Contains(s1)){
				h.Add(s0);
				h.Add(s1);
				route[now] = j;
				dfs(now+1);
				route[now] = 0;
				h.Remove(s0);
				h.Remove(s1);
			}
		}
	}
	
	
	
	int N;
	String[] S;
	public Sol(){
		N = ri();
		S = new String[N];
		for(int i=0;i<N;i++) S[i] = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0