結果
| 問題 |
No.372 It's automatic
|
| コンテスト | |
| ユーザー |
akakimidori
|
| 提出日時 | 2018-08-30 01:58:48 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 357 ms / 6,000 ms |
| コード長 | 852 bytes |
| コンパイル時間 | 426 ms |
| コンパイル使用メモリ | 30,592 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-13 19:45:34 |
| 合計ジャッジ時間 | 5,523 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include<stdio.h>
#include<stdlib.h>
void run(void){
char *s=(char *)malloc(sizeof(char)*(10000+1));
scanf("%s",s);
int m;
scanf("%d",&m);
short *mul=(short *)malloc(sizeof(short)*10*m);
int i,j;
for(i=0;i<10;i++){
for(j=0;j<m;j++){
mul[i*m+j]=(10*j+i)%m;
}
}
int *now=(int *)calloc(m,sizeof(int));
int *next=(int *)calloc(m,sizeof(int));
int cnt=0;
const int mod=1000000007;
int n;
for(n=0;s[n]!='\0';n++){
int d=s[n]-'0';
for(j=0;j<m;j++) next[j]=now[j];
for(j=0;j<m;j++){
int index=mul[d*m+j];
int t=next[index]+now[j];
next[index]=t>=mod?t-mod:t;
}
if(d==0){
cnt++;
} else{
next[d%m]=next[d%m]==mod-1?0:next[d%m]+1;
}
int *swap=now;
now=next;
next=swap;
}
printf("%d\n",(now[0]+cnt)%mod);
}
int main(void){
run();
return 0;
}
akakimidori