結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
40,892 KB
testcase_01 AC 118 ms
41,516 KB
testcase_02 AC 111 ms
40,292 KB
testcase_03 AC 120 ms
41,284 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 123 ms
41,608 KB
testcase_17 AC 119 ms
41,488 KB
testcase_18 AC 140 ms
40,340 KB
testcase_19 AC 120 ms
41,120 KB
testcase_20 AC 122 ms
41,492 KB
testcase_21 AC 370 ms
81,496 KB
testcase_22 AC 334 ms
81,876 KB
testcase_23 AC 321 ms
81,512 KB
testcase_24 AC 356 ms
81,576 KB
testcase_25 AC 326 ms
81,384 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[][] 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
		 */
		if(str.charAt(0)-'0'==0){
			dp[str.length()-1][0]++;
		}else{
			dp[0][(str.charAt(0)-'0')%m]++;
		}
		for(int i=1;i<str.length();i++){
			/*
			 * dp[i][]を考える
			 */
			{
				for(int j=0;j<m;j++){
					dp[i][(j*10+str.charAt(i)-'0')%m]+=dp[i-1][j];
					dp[i][(j*10+str.charAt(i)-'0')%m]%=MOD;
				}
				if(str.charAt(i)-'0'!=0){
					dp[i][(str.charAt(i)-'0')%m]++;
				}else if(str.charAt(i)-'0'==0){
					dp[str.length()-1][0]++;
				}
				for(int j=0;j<m;j++){
					dp[i][j]+=dp[i-1][j];
					dp[i][j]%=MOD;
				}
			}
		}
		System.out.println(dp[str.length()-1][0]%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