結果

問題 No.1909 Detect from Substrings
ユーザー 37zigen37zigen
提出日時 2022-04-22 21:28:40
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,262 bytes
コンパイル時間 2,323 ms
コンパイル使用メモリ 75,304 KB
実行使用メモリ 773,780 KB
最終ジャッジ日時 2023-09-06 07:47:19
合計ジャッジ時間 11,141 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
60,452 KB
testcase_01 AC 124 ms
55,944 KB
testcase_02 AC 124 ms
55,756 KB
testcase_03 AC 1,184 ms
61,308 KB
testcase_04 AC 316 ms
64,284 KB
testcase_05 AC 430 ms
65,020 KB
testcase_06 AC 457 ms
65,332 KB
testcase_07 AC 593 ms
67,200 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main implements Runnable { //Runnableを実装する
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行
    }
    
    int dfs(char[][] str, char[] ans, int pos, int[] equiv) {
    	int ret=0;
    	if (pos==ans.length) return 1;
    	for (int i=0;i<26;++i) {
    		ans[pos]=(char)(i+'a');
    		int[] nequiv=Arrays.copyOf(equiv, equiv.length);
    		boolean ok=true;
    		for (int j=0;j<str.length;++j) {
    			if (equiv[j] < str[j].length && ans[pos]==str[j][equiv[j]]) ++nequiv[j];
    			ok &= (pos+1)-nequiv[j] <= 1;
    		}
    		if (ok) ret += dfs(str, ans, pos+1, nequiv);
    	}
    	return ret;
    }
	
	public void run() {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		
		int N=sc.nextInt();
		int M=sc.nextInt();
		char[][] str=new char[N][M];
		for (int i=0;i<N;++i) str[i]=sc.next().toCharArray();
		int[] equiv=new int[M];
		char[] ans=new char[M+1];
		pw.println(dfs(str, ans, 0, equiv));
		pw.close();
		
	}	
	
	void tr(Object ... o) {System.out.println(Arrays.deepToString(o));}
}
0