Submission #6438416


Source Code Expand

#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = INF + 7;

int dp[100001][2][100];

int main(void){
    int D;
    string N;
    cin >> D >> N;

    int len = (int)N.size();

    dp[0][0][0] = 1;
    for(int i = 0; i < len; i++){
        for(int smaller = 0; smaller < 2; smaller++){
            int limit = smaller ? 9 : N[i] - '0';
            for(int j = 0; j < D; j++){
                for(int k = 0; k <= limit; k++){
                    (dp[i+1][smaller or k < limit][(j+k)%D] += dp[i][smaller][j]) %= MOD;
                }
            }
        }
    }

    cout << (dp[len][0][0] + dp[len][1][0] - 1) % MOD << '\n';

    return 0;
}

Submission Info

Submission Time
Task E - 数
User yna87
Language C++14 (GCC 5.4.1)
Score 4
Code Size 810 Byte
Status AC
Exec Time 130 ms
Memory 8448 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 2 ms 256 KB
01 AC 79 ms 8448 KB
02 AC 130 ms 8448 KB
90 AC 1 ms 256 KB
91 AC 1 ms 256 KB