結果
| 問題 |
No.372 It's automatic
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-05-14 13:51:39 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,379 bytes |
| コンパイル時間 | 2,345 ms |
| コンパイル使用メモリ | 79,232 KB |
| 実行使用メモリ | 748,252 KB |
| 最終ジャッジ日時 | 2024-10-06 02:29:01 |
| 合計ジャッジ時間 | 15,428 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 MLE * 12 |
ソースコード
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("-------------");
}
}