-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwip3.cpp
More file actions
117 lines (105 loc) · 2.77 KB
/
wip3.cpp
File metadata and controls
117 lines (105 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <bits/stdc++.h>
using namespace std;
//#include <ext/rope>
//using namespace __gnu_cxx;
#include <ext/pb_ds/assoc_container.hpp>
#include <stdlib.h>
using namespace __gnu_pbds;
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#define inputJunk ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug cout<<"HERE"<<endl;
#define ell "\n"
//#define x real()
//#define y imag()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<int, pi> trip;
typedef pair<pll, ll> tripll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<trip> vtrip;
typedef vector<tripll> vtripll;
typedef complex<double> point;
const int INF = 1e9+1212;
const ll INFLL = 1e12+1212;
const ll P = 9973, M = 1e9+9;
const int MM = 2e5+5; int mod = 1e9+7;//99824435
string k; int d;
int main(){
inputJunk
cin>>k>>d;
int sz = k.size();
vector<vll> dp (k.size()+1,vll(d, 0LL));
vector<vll> pp (k.size()+1,vll(d, 0LL));
dp[0][0] = 1;
for(int j = 1;j<=k.size();j++){
for(int k = 0;k<d;k++){
for(int i = 0;i<=9;i++){
if(j==1&&i==0)continue;
dp[j][(k+i)%d] = (dp[j][(k+i)%d]+dp[j-1][k])%mod;
}
}
}
pp[0][0] = 1;
for(int j = 1;j<=k.size();j++){
for(int k = 0;k<d;k++){
pp[j][k] = (pp[j-1][k]+dp[j][k])%mod;
}
}
for(int j = 1;j<=k.size();j++){
for(int k = 0;k<d;k++){
cout<<dp[j][k]<<" ";
}cout<<ell;
}
for(int j = 1;j<=k.size();j++){
for(int k = 0;k<d;k++){
cout<<pp[j][k]<<" ";
}cout<<ell;
}
ll ans = 0;
int digit_sum = 0;
for(int i = sz-1;i>=0;i--){
ans+=(k[0]-'0')*pp[i][digit_sum];
ans%=mod;
cout<<(k[0]-'0')<<" "<<pp[i][digit_sum]<<" "<<ans<<ell;
digit_sum-=(k[0]-'0');
while(digit_sum<0)digit_sum+=d;
k = k.substr(1, k.size()-1);
}
cout<<ans<<ell;
}
/*CUSTOM TEST CASE 1
*/
/*CUSTOM TEST CASE 2
*/
/*CUSTOM TEST CASE 3
*/
/*Comments of Shame
- floating error (use integer division instead)
- cin vs getline
- upperbound and lowerbound returns iteratorsf
- use long long when number is big enough
- for dp invalid cases needs to be skipped
- some base cases won't work (review cow poetry)
- always check bounds, some TLE are due to incorrect bounds!
- dont mess up return types
= RESET ARRAYS!!!!!!!!!!
- USE UR BRAIN
- INF setting problems
- push vs pb
- check if things are used properly
- read the PROBLEM (directed vs undirected graph)
*/
/*
freopen("time.in","r", stdin);
freopen("time.out","w", stdout);
*/