結果

問題 No.372 It's automatic
ユーザー 37zigen37zigen
提出日時 2016-05-14 13:51:39
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,379 bytes
コンパイル時間 2,613 ms
コンパイル使用メモリ 79,280 KB
実行使用メモリ 747,672 KB
最終ジャッジ日時 2024-04-15 21:24:18
合計ジャッジ時間 18,238 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
54,068 KB
testcase_01 AC 139 ms
54,180 KB
testcase_02 AC 144 ms
54,216 KB
testcase_03 AC 139 ms
54,180 KB
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
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 AC 146 ms
54,120 KB
testcase_17 AC 141 ms
53,956 KB
testcase_18 AC 141 ms
53,888 KB
testcase_19 AC 139 ms
54,180 KB
testcase_20 AC 141 ms
54,124 KB
testcase_21 AC 371 ms
113,884 KB
testcase_22 AC 365 ms
113,620 KB
testcase_23 AC 368 ms
113,364 KB
testcase_24 AC 360 ms
113,664 KB
testcase_25 AC 365 ms
113,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().solve();
	}
	final int MOD=1_000_000_000+7;
	void solve(){
		Scanner sc=new Scanner(System.in);
		String str=sc.next();
		int m=sc.nextInt();
		
		int[] from=new int[m];
		int[] to=new int[m];
		
		int[][] dp=new int[str.length()][m];
		/*
		 * dp[i][j]=先頭からi+1文字までの部分文字列を考えたとき、
		 * 余りjとなるものがいくつ存在するか。
		 * ex.1021213421 (m=3)
		 * dp[0][1]=1,dp[0][1]=0,dp[0][2]=0
		 */
		
		int ZERO=0;
		if(str.charAt(0)-'0'==0){
			ZERO++;
		}else{
			from[(str.charAt(0)-'0')%m]++;
		}
		for(int i=1;i<str.length();i++){
			/*
			 * dp[i][]を考える
			 */
			{
				for(int j=0;j<m;j++){
					to[(j*10+str.charAt(i)-'0')%m]+=from[j];
					to[(j*10+str.charAt(i)-'0')%m]%=MOD;
				}
				if(str.charAt(i)-'0'!=0){
					to[(str.charAt(i)-'0')%m]++;
				}else if(str.charAt(i)-'0'==0){
					ZERO++;
				}
				for(int j=0;j<m;j++){
					to[j]+=from[j];
					to[j]%=MOD;
				}
			}
			from=to;to=new int[m];
		}
		System.out.println((from[0]+ZERO)%MOD);
	}
	void showMt(int[][] a){
		System.out.println("-------------");
		for(int i=0;i<a.length;i++){
			for(int j=0;j<a[0].length;j++){
				System.out.print(a[i][j]+(j!=a[0].length-1?" ":"\n"));
			}
		}
		System.out.println("-------------");
	}
}
0