結果

問題 No.372 It's automatic
ユーザー akakimidoriakakimidori
提出日時 2018-08-30 02:51:43
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 502 ms / 6,000 ms
コード長 732 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 29,760 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 20:54:41
合計ジャッジ時間 7,398 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 0 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 500 ms
4,348 KB
testcase_05 AC 497 ms
4,348 KB
testcase_06 AC 493 ms
4,348 KB
testcase_07 AC 491 ms
4,348 KB
testcase_08 AC 494 ms
4,348 KB
testcase_09 AC 491 ms
4,352 KB
testcase_10 AC 491 ms
4,348 KB
testcase_11 AC 486 ms
4,348 KB
testcase_12 AC 493 ms
4,348 KB
testcase_13 AC 496 ms
4,352 KB
testcase_14 AC 493 ms
4,348 KB
testcase_15 AC 502 ms
4,352 KB
testcase_16 AC 0 ms
4,352 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 0 ms
4,348 KB
testcase_20 AC 0 ms
4,348 KB
testcase_21 AC 29 ms
4,348 KB
testcase_22 AC 29 ms
4,348 KB
testcase_23 AC 28 ms
4,348 KB
testcase_24 AC 29 ms
4,352 KB
testcase_25 AC 28 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
  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';
    int i,j;
    for(j=0;j<m;j++) next[j]=now[j];
    j=0;
    while(j<m){
      for(i=(10*j+d)%m;j<m && i<m;i+=10,j++){
	int t=next[i]+now[j];
	next[i]=t<mod?t:t-mod;
      }
    }
    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;
}
0