結果

問題 No.372 It's automatic
ユーザー 37zigen37zigen
提出日時 2016-05-14 13:52:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,346 ms / 6,000 ms
コード長 1,340 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 79,632 KB
実行使用メモリ 46,392 KB
最終ジャッジ日時 2024-04-15 21:25:02
合計ジャッジ時間 33,142 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
41,160 KB
testcase_01 AC 110 ms
40,136 KB
testcase_02 AC 119 ms
41,156 KB
testcase_03 AC 109 ms
40,480 KB
testcase_04 AC 2,204 ms
45,628 KB
testcase_05 AC 2,320 ms
46,016 KB
testcase_06 AC 2,311 ms
46,308 KB
testcase_07 AC 2,274 ms
45,224 KB
testcase_08 AC 2,209 ms
45,508 KB
testcase_09 AC 2,283 ms
45,080 KB
testcase_10 AC 2,200 ms
45,496 KB
testcase_11 AC 2,289 ms
45,224 KB
testcase_12 AC 2,320 ms
45,376 KB
testcase_13 AC 2,282 ms
45,584 KB
testcase_14 AC 2,346 ms
46,392 KB
testcase_15 AC 2,308 ms
45,112 KB
testcase_16 AC 121 ms
41,024 KB
testcase_17 AC 112 ms
40,364 KB
testcase_18 AC 120 ms
41,240 KB
testcase_19 AC 112 ms
40,396 KB
testcase_20 AC 119 ms
41,412 KB
testcase_21 AC 293 ms
45,848 KB
testcase_22 AC 299 ms
45,848 KB
testcase_23 AC 297 ms
45,956 KB
testcase_24 AC 276 ms
46,080 KB
testcase_25 AC 304 ms
45,760 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];
		
		/*
		 * 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