結果

問題 No.372 It's automatic
ユーザー yaoshimaxyaoshimax
提出日時 2016-05-14 17:20:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,287 ms / 6,000 ms
コード長 803 bytes
コンパイル時間 428 ms
コンパイル使用メモリ 57,516 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 21:31:07
合計ジャッジ時間 16,770 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1,257 ms
6,944 KB
testcase_05 AC 1,264 ms
6,940 KB
testcase_06 AC 1,280 ms
6,940 KB
testcase_07 AC 1,262 ms
6,940 KB
testcase_08 AC 1,255 ms
6,940 KB
testcase_09 AC 1,252 ms
6,940 KB
testcase_10 AC 1,270 ms
6,940 KB
testcase_11 AC 1,264 ms
6,940 KB
testcase_12 AC 1,283 ms
6,944 KB
testcase_13 AC 1,287 ms
6,944 KB
testcase_14 AC 1,286 ms
6,944 KB
testcase_15 AC 1,281 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 65 ms
6,944 KB
testcase_22 AC 68 ms
6,940 KB
testcase_23 AC 66 ms
6,940 KB
testcase_24 AC 65 ms
6,944 KB
testcase_25 AC 66 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
using namespace std;
long long dp[2][20001];
int main(){
   string s;
   int M;
   cin >> s >> M;
   long long ans=0;
   int mod=1000000007;
   int size = s.size();
   memset(dp,0,sizeof(dp));
   for( int i = 0 ; i < size; i++ ){
      for( int m=0 ; m <M; m++ ){
         dp[1-i%2][m]=0;
      }
      if( s[i]=='0' ){
         ans += 1;
      }
      else{
         dp[1-i%2][(s[i]-'0')%M]+=1;
      }
      for( int m = 0 ; m < M; m++ ){
         int n = (m*10+s[i]-'0')%M;
         dp[1-i%2][m]+=dp[i%2][m];
         dp[1-i%2][m]%=mod;
         dp[1-i%2][n]+=dp[i%2][m];
         dp[1-i%2][n]%=mod;
      }
      //for( int m=0; m<M; m++){
      //   cout << i+1<<","<<m<<": "<<dp[1-i%2][m]<<endl;
      //}
   }
   cout << (ans+dp[size%2][0])%mod << endl;

}
0