Submission #1242249


Source Code Expand

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

long long M=1000000007;
int main(int argc, char const *argv[]) {
  int d;cin>>d;
  string s;cin>>s;
  int n=s.length();
  vector<vector<long long>> dp1(n+1,vector<long long>(d)),dp2(n+1,vector<long long>(d));
  dp1[0][0]=1;
  dp2[0][0]=1;
  for(int i=0;i<n;++i){
    for(int j=0;j<d;++j){
      for(int k=0;k<=9;++k){
        dp1[i+1][(j+k)%d]+=dp1[i][j];
        dp1[i+1][(j+k)%d]%=M;
      }
      int p=stoi(s.substr(n-1-i,1));
      for(int k=0;k<p;++k){
        dp2[i+1][j]+=dp1[i][(j-k+10*d)%d];
        dp2[i+1][j]%=M;
      }
      dp2[i+1][(j+p)%d]+=dp2[i][j];
      dp2[i+1][(j+p)%d]%=M;
    }
  }
  cout<<dp2[n][0]-1<<endl;
  return 0;
}

Submission Info

Submission Time
Task E - 数
User pillow97
Language C++14 (GCC 5.4.1)
Score 4
Code Size 904 Byte
Status AC
Exec Time 300 ms
Memory 16128 KB

Judge Result

Set Name All
Score / Max Score 4 / 4
Status
AC × 5
Set Name Test Cases
All 00, 01, 02, 90, 91
Case Name Status Exec Time Memory
00 AC 4 ms 384 KB
01 AC 181 ms 10112 KB
02 AC 300 ms 16128 KB
90 AC 1 ms 256 KB
91 AC 1 ms 256 KB