結果

問題 No.1909 Detect from Substrings
ユーザー 37zigen37zigen
提出日時 2022-04-22 21:41:03
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,480 bytes
コンパイル時間 2,296 ms
コンパイル使用メモリ 75,876 KB
実行使用メモリ 769,580 KB
最終ジャッジ日時 2023-09-06 08:02:09
合計ジャッジ時間 25,051 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
62,424 KB
testcase_01 AC 124 ms
55,812 KB
testcase_02 AC 124 ms
55,900 KB
testcase_03 AC 325 ms
59,860 KB
testcase_04 AC 318 ms
60,332 KB
testcase_05 AC 438 ms
60,900 KB
testcase_06 AC 542 ms
63,256 KB
testcase_07 AC 583 ms
65,436 KB
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 593 ms
74,176 KB
testcase_19 AC 584 ms
65,740 KB
testcase_20 AC 587 ms
65,564 KB
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
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');
    		boolean ok=true;
    		for (int j=0;j<str.length;++j) {
    			int add=0;
    			if (equiv[j] < str[j].length && ans[pos]==str[j][equiv[j]]) ++add;
    			ok &= (pos+1)-(equiv[j]+add) <= 1;
    		}
    		if (ok) {
    			int[] nequiv=Arrays.copyOf(equiv, equiv.length);
        		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;
        		}
        		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