text
stringlengths 49
983k
|
|---|
//To debug : g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
//take care of precedence rule of operators
//do not forget to change the sizes of arrays and value of contants and other things after debugging
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)
#define SZ(x) (ll)(x.size())
//comment the below if not required
/*
#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second
*/
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
//cout<<"Case #"<<c<<": "<<ans<<"\n" ;
const ll N = 2e5+1;
ll n,m;
ll M[N],a[N],ps[N],ans[N],val,res,i,sz;
vector<pair<ll,ll>> v;
int main()
{
IOS;
ll t,s,temp,l,r,mid,mx;
cin>>t;
while(t--)
{
cin>>n>>m;
s = 0;
v.clear();
rep(i,1,n+1){
cin>>a[i];
s+=a[i];
if(s>0)
v.pb({s,i});
}
rep(i,1,m+1){
cin>>M[i];
}
sort(v.begin(),v.end());
sz = SZ(v);
if(sz==0)
{
rep(i,1,m+1)
cout<<-1<<" ";
cout<<"\n";
continue;
}
mx = v[sz-1].first;
temp = LLONG_MAX;
for(i=sz-1;i>=0;--i)
{
temp = min(temp,v[i].second);
ps[i]=temp;
}
for(i=1;i<=m;++i)
{
ans[i] = 0;
if(M[i]>mx)
{
if(s<=0)
{
ans[i]=-1;
continue;
}
temp = (M[i]-mx+s-1)/s;
ans[i] = temp*n;
M[i] -= temp*s;
}
l = 0 , r = sz-1;
res = LLONG_MAX;
while(l<=r)
{
mid = (l+r)/2;
if(v[mid].first>=M[i])
{
res = ps[mid];
r = mid-1;
}
else
{
l = mid+1;
}
}
ans[i] += res-1;
}
for(i=1;i<=m;++i)
cout<<ans[i]<<" ";
cout<<"\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ps push
#define in insert
#define f first
#define s second
#define ca(v) for(auto i:v) cout<<i<<" ";
#define nl cout<<"\n"
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b/gcd(a, b))
int xm[4] = {-1, 1, 0, 0};
int ym[4] = {0, 0, -1, 1};
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
const ll POW = 9973;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int t;
cin>>t;
while(t--){
int n, m;
cin>>n>>m;
ll ar[n];
vector<ll> sm(n, 0);
vector<ll> mx(n, 0);
for(int i=0; i<n; i++) cin>>ar[i];
for(int i=0; i<n; i++){
if(i) {
sm[i] = sm[i-1];
mx[i] = mx[i-1];
}
sm[i] += ar[i];
mx[i] = max(mx[i], sm[i]);
}
for(int i=0; i<m; i++){
ll x; cin>>x;
ll ans = -1;
if(sm[n-1]>0 && (x-mx[n-1])>0){
ans += n * (((x-mx[n-1]+sm[n-1]-1)/sm[n-1]));
x -= sm[n-1] * ((x-mx[n-1]+sm[n-1]-1)/sm[n-1]);
}
if(x==0) {cout<<ans<<" "; continue;}
auto it = lower_bound(all(mx), x);
if(it==mx.end()) cout<<-1<<" ";
else cout<<ans + (it - mx.begin())+1<<" ";
}
nl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n, m;
cin >> n >> m;
vector<ll> a(n);
ll allSum = 0;
vector<ll> pref;
vector<int> ind;
int curInd = 0;
for (ll &e : a) {
cin >> e;
allSum += e;
if (pref.empty() || allSum > pref.back()) {
pref.push_back(allSum);
ind.push_back(curInd);
}
curInd++;
}
for (int q = 0; q < m; q++) {
ll x;
cin >> x;
if (pref.back() < x && allSum <= 0) {
cout << -1 << " ";
continue;
}
ll needTimes = 0;
if (pref.back() < x) {
needTimes = (x - pref.back() + allSum - 1) / allSum;
}
x -= needTimes * allSum;
cout << needTimes * n + ind[lower_bound(pref.begin(), pref.end(), x) - pref.begin()] << " ";
}
cout << "\n";
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "trace.h"
#else
#define trace(args...)
#endif
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
const int inf = 1e9 + 7;
struct seg_tree {
vector<ll> t;
int n;
void init(int m) {
n = m;
t.assign(4 * n, 0);
}
int query_aux(int v, int tl, int tr, int l, int r, ll x) {
if (l > r || t[v] < x) return -1;
if (tl == tr) return tl;
int tm = (tl + tr) / 2;
int res = query_aux(v * 2, tl, tm, l, min(r, tm), x);
if (res == -1) res = query_aux(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, x);
return res;
}
void update_aux(int v, int tl, int tr, int pos, ll new_val) {
if (tl == tr) {
t[v] = new_val;
return;
}
int tm = (tl + tr) / 2;
if (pos <= tm)
update_aux(v * 2, tl, tm, pos, new_val);
else
update_aux(v * 2 + 1, tm + 1, tr, pos, new_val);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
void update(int i, ll x) {
return update_aux(1, 0, n - 1, i, x);
}
int query(int l, int r, ll x) {
return query_aux(1, 0, n - 1, l, r, x);
}
};
void solve(int test) {
seg_tree stree;
int n, m;
cin >> n >> m;
vector<ll> a(n + 1, 0);
stree.init(n + 1);
stree.update(0, 0);
ll mx = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
stree.update(i, a[i]);
mx = max(mx, a[i]);
}
trace(a);
for (int i = 0, x; i < m; i++) {
cin >> x;
int res = stree.query(0, n, x);
if (res == -1) {
if (a[n] <= 0) {
cout << -1;
} else {
int q = 1 + (x - mx - 1) / a[n];
x -= q * a[n];
res = stree.query(0, n, x);
ll ans = 1LL * q * n;
ans += (res - 1);
cout << ans;
}
} else {
cout << (res - 1);
}
cout << ' ';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << ": ";
solve(i);
cout << '\n';
}
}
|
#include<bits/stdc++.h>
using namespace std;
//https://blog.csdn.net/Phoenix_ZengHao/article/details/113833938
typedef long long LL;
const int maxn=2e5+50;
LL n,m,T;
LL a[maxn],sum[maxn],maxx[maxn],ans[maxn];
int main()
{
cin>>T;
while(T--)
{
cin>>n>>m;
memset(maxx,0,sizeof(maxx));
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum[i]=sum[i-1]+a[i];
maxx[i]=max(maxx[i-1],sum[i]);
}
for(int i=1;i<=m;i++)
{
LL x;
cin>>x;
if(x<=maxx[n])
{
LL t=lower_bound(maxx+1,maxx+1+n,x)-maxx;
cout<<t-1<<' ';
}
else
{
if(sum[n]<=0)
{
cout<<-1<<' ';
}
else
{
LL d=x-maxx[n];
LL tot=ceil(d*1.0/sum[n]);
x=x-tot*sum[n];
LL t=lower_bound(maxx+1,maxx+1+n,x)-maxx;
t=t+tot*n-1;
cout<<t<<' ';
}
}
}
cout<<'\n';
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define Fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define fWrite freopen ("out.txt","w",stdout);
#define TC int t;cin >> t;FOR(tc,1,t)
#define LL long long
#define ULL unsigned long long
#define ff first
#define ss second
#define pb push_back
#define pii pair<LL,int>
#define all(a) a.begin(),a.end()
#define MEM(a,x) memset(a,x,sizeof(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,b) for(int i=0;i<b;i++)
const int N = 2e5 + 5;
int n,m;
int tree[4*N];
LL arr[N];
vector<pii>csum;
inline void build(int L,int R,int pos)
{
if(L==R)
{
tree[pos] = csum[L].ss;
return;
}
int mid=(L+R)/2;
build(L,mid,pos*2+1);
build(mid+1,R,pos*2+2);
tree[pos]=min(tree[pos*2+1],tree[pos*2+2]);
return;
}
inline int query(int ql,int qr,int L,int R,int pos)
{
if(ql>R or qr<L)
return 1e9;
else if(ql<=L and qr>=R)
return tree[pos];
int mid=(L+R)/2;
int p=query(ql,qr,L,mid,2*pos+1);
int q=query(ql,qr,mid+1,R,2*pos+2);
return min(p,q);
}
int call(LL x){
int idx = lower_bound(all(csum),pii(x,-1)) - csum.begin();
return query(idx,n-1,0,n-1,0);
}
int main()
{
Fast
TC{
cin >> n >> m;
LL sum = 0, mx = -1e18;
csum.clear();
REP(i,n) {
cin >> arr[i];
sum += arr[i];
csum.pb({sum,i});
if(sum>mx) {
mx = sum;
}
}
sort(all(csum));
REP(i,4*n) tree[i] = 1e8;
build(0,n-1,0);
FOR(i,1,m){
LL x;
cin >> x;
if(x<=mx){
cout << call(x) << ' ';
}
else{
if(sum<=0) cout << -1 << ' ';
else{
LL diff = (x - mx);
if(diff%sum==0) diff = (diff/sum);
else diff = (diff/sum) + 1;
x -= diff * sum;
//cout << "=== " << mx << ' ' << sum << ' ' << x << '\n';
cout << n * diff + call(x) << ' ';
}
}
}
cout << '\n';
}
}
|
#include <bits/stdc++.h>
// #include <atcoder/all>
//using namespace atcoder;
//tabaicho see https://boostjp.github.io/tips/multiprec-int.html
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// cpp_int
// int128_t
// int256_t
// int512_t
// int1024_t
// uint128_t
// uint256_t
// uint512_t
// uint1024_t
#define int long long
#define inf 1000000007
// #define inf 998244353
#define pa pair<int,int>
#define ll long long
#define PI 3.14159265358979323846
#define mp make_pair
#define pb push_back
#define EPS (1e-8)
using namespace std;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,-1,1,1,-1};
class pa3{
public:
int x;
int y,z;
pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
bool operator < (const pa3 &p) const{
if(x!=p.x) return x<p.x;
if(y!=p.y) return y<p.y;
return z<p.z;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator > (const pa3 &p) const{
if(x!=p.x) return x>p.x;
if(y!=p.y) return y>p.y;
return z>p.z;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator == (const pa3 &p) const{
return x==p.x && y==p.y && z==p.z;
}
bool operator != (const pa3 &p) const{
return !( x==p.x && y==p.y && z==p.z);
}
};
class pa4{
public:
int x;
int y,z,w;
pa4(int x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
bool operator < (const pa4 &p) const{
if(x!=p.x) return x<p.x;
if(y!=p.y) return y<p.y;
if(z!=p.z)return z<p.z;
return w<p.w;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator > (const pa4 &p) const{
if(x!=p.x) return x>p.x;
if(y!=p.y) return y>p.y;
if(z!=p.z)return z>p.z;
return w>p.w;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator == (const pa4 &p) const{
return x==p.x && y==p.y && z==p.z &&w==p.w;
}
};
class pa2{
public:
int x,y;
pa2(int x=0,int y=0):x(x),y(y) {}
pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
bool operator < (const pa2 &p) const{
return y != p.y ? y<p.y: x<p.x;
}
bool operator > (const pa2 &p) const{
return x != p.x ? x<p.x: y<p.y;
}
bool operator == (const pa2 &p) const{
return abs(x-p.x)==0 && abs(y-p.y)==0;
}
bool operator != (const pa2 &p) const{
return !(abs(x-p.x)==0 && abs(y-p.y)==0);
}
};
string itos( int i ) {
ostringstream s ;
s << i ;
return s.str() ;
}
int Gcd(int v,int b){
if(v==0) return b;
if(b==0) return v;
if(v>b) return Gcd(b,v);
if(v==b) return b;
if(b%v==0) return v;
return Gcd(v,b%v);
}
int mod;
int extgcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int d = extgcd(b, a%b, y, x);
y -= a/b * x;
return d;
}
pa operator+(const pa & l,const pa & r) {
return {l.first+r.first,l.second+r.second};
}
pa operator-(const pa & l,const pa & r) {
return {l.first-r.first,l.second-r.second};
}
ostream& operator<<(ostream& os, const vector<int>& VEC){
for(auto v:VEC)os<<v<<" ";
return os;
}
ostream& operator<<(ostream& os, const pa& PAI){
os<<PAI.first<<" : "<<PAI.second;
return os;
}
ostream& operator<<(ostream& os, const pa3& PAI){
os<<PAI.x<<" : "<<PAI.y<<" : "<<PAI.z;
return os;
}
ostream& operator<<(ostream& os, const pa4& PAI){
os<<PAI.x<<" : "<<PAI.y<<" : "<<PAI.z<<" : "<<PAI.w;
return os;
}
ostream& operator<<(ostream& os, const vector<pa>& VEC){
for(auto v:VEC)os<<v<<" ";
return os;
}
int beki(int wa,int rr,int warukazu){
if(rr==0) return 1%warukazu;
if(rr==1) return wa%warukazu;
wa%=warukazu;
if(rr%2==1) return ((ll)beki(wa,rr-1,warukazu)*(ll)wa)%warukazu;
ll zx=beki(wa,rr/2,warukazu);
return (zx*zx)%warukazu;
}
int pr[2100000];
int inv[2100000];
int comb(int nn,int rr){
if(rr<0 || rr>nn || nn<0) return 0;
int r=pr[nn]*inv[rr];
r%=mod;
r*=inv[nn-rr];
r%=mod;
return r;
}
void gya(int ert){
pr[0]=1;
for(int i=1;i<=ert;i++){
pr[i]=((ll)pr[i-1]*i)%mod;
}
inv[ert]=beki(pr[ert],mod-2,mod);
for(int i=ert-1;i>=0;i--){
inv[i]=(ll)inv[i+1]*(i+1)%mod;
}
}
// cin.tie(0);
// ios::sync_with_stdio(false);
//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
//sort(ve.begin(),ve.end(),greater<int>());
// mt19937(clock_per_sec);
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ;
void solve(){
int n;
cin>>n;
int q;
cin>>q;
vector<int>ve(n);
for(auto &v:ve)cin>>v;
vector<int>rui=ve;
for(int i=1;i<n;i++)rui[i]+=rui[i-1];
int T=rui.back();
for(int i=1;i<n;i++)rui[i]=max(rui[i],rui[i-1]);
while(q--){
int x;
cin>>x;
if(rui.back()>=x){
cout<<lower_bound(rui.begin(),rui.end(),x)-rui.begin()<<" ";
continue;
}
if(T<=0){
cout<<-1<<" ";
continue;
}
int sa=x-rui.back();
int kai=sa/T+!!(sa%T);
int ans=n*kai;
x-=T*kai;
cout<<lower_bound(rui.begin(),rui.end(),x)-rui.begin()+ans<<" ";
}
cout<<endl;
}
signed main(){
mod=inf;
cin.tie(0);
//solve1();
ios::sync_with_stdio(false);
int n=1;
cin>>n;
for(int i=0;i<n;i++)solve();
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <fstream>
#include <vector>
#include <queue>
#include <stack>
#include <sstream>
#include <list>
#include <map>
#include <set>
#include <limits>
#include <random>
#include <functional>
#include <unordered_set>
#include <unordered_map>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
using namespace std;
const int N = 100010;
const int M = 200010;
const int MOD = 1000000007;
const int INF = 1009000999;
const ll LINF = (1ll << 60) + 1337;
const ld EPS = 0.00000001;
void build(vi& a, vi & ans, int l, int r, int depth = 0) {
if (l >= r) return;
int id = max_element(a.begin() + l, a.begin() + r) - a.begin();
ans[id] = depth;
build(a, ans, l, id, depth + 1);
build(a, ans, id + 1, r, depth + 1);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef _DEBUG
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
//#ifndef _DEBUG
// freopen("cubroot.in", "r", stdin); freopen("cubroot.out", "w", stdout);
//#endif
int tt;
cin >> tt;
while (tt--) {
int n, m;
cin >> n >> m;
vl a(n);
vl ps(n + 1, 0);
map<ll, ll> imin;
map<ll, ll> ss;
for (int i = 0; i < n; i++) {
cin >> a[i];
ps[i + 1] = ps[i] + a[i];
if (imin.find(ps[i + 1]) == imin.end()) imin[ps[i + 1]] = i;
}
ll pref = INF;
for (auto i = imin.rbegin(); i != imin.rend(); i++) {
ss[i->first] = min(pref, i->second);
pref = min(pref, i->second);
}
while (m--) {
ll x;
cin >> x;
if (ss.lower_bound(x) == ss.end()) {
if (ps[n] <= 0) cout << "-1 ";
else {
ll rotate = (x - ss.rbegin()->first) / ps[n] + ((x - ss.rbegin()->first) % ps[n] ? 1ll : 0ll);
ll res = rotate * n;
ll ost = x - rotate * ps[n];
//if (imin.lower_bound(ost) == imin.end()) {
// res += n;
// ost -= ps[n];
//}
res += ss.lower_bound(ost)->second;
cout << res << " ";
}
}
else {
cout << ss.lower_bound(x)->second << " ";
}
}
cout << "\n";
}
}
/*
Important stuff
- int overflow
- array bounds
- special cases (n=1, max n) maybe adhoc problem
- doubles are read for a long time (4 * 10 ^ 5 danger GNU vs MS ICPC 2020 1/4)
- don't get stuck on one approach
- don't get stuck on one problem
- recheck submissions if near the end of the tournament and there is nothing to do
- do something instead of nothing and stay organized
*/
|
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main()
{
int t; cin >> t;
int vivod = 0;
for (int i = 0; i < t; ++i){
int n, m; cin >> n >> m;
vector<pair<long long, long long>> prirost;
vector <long long> mas(n);
long long prirost_max = 0, prirost_cikl=0;
for (int x = 0; x < n; ++x){
cin >> mas[x];
prirost_cikl += mas[x];
prirost_max = (prirost_max > prirost_cikl ? prirost_max : prirost_cikl);
if (prirost_cikl > 0){
if (prirost.size() == 0) prirost.push_back(make_pair(prirost_cikl, x));
else if (prirost_cikl > prirost[prirost.size() - 1].first) prirost.push_back(make_pair(prirost_cikl, x));
}
}
for (int x = 0; x < m; ++x){
long long a, ch=0; cin >> a;
if (prirost_max < a and prirost_cikl<= 0) cout << -1 << " ";
else{
a -= prirost_max;
if (a > 0){ch += (a / prirost_cikl); ch += (a % prirost_cikl != 0 ? 1 : 0);}
a -= (ch * prirost_cikl);
a += prirost_max;
int nach = 0, konec = prirost.size(), ser = 0;
while(konec - nach > 1){
ser = (nach + konec) / 2;
if (a >= prirost[ser].first) nach = ser;
else konec = ser;
}
ser = (nach + konec) / 2;
while (ser > 0 and a <= prirost[ser - 1].first) ser-=1;
while (a > prirost[ser].first and ser < prirost.size()) ser += 1;
ch *= n;
int ch1 = ch;
if (prirost.size()) ch += prirost[ser].second;
if (t == 2000 and ch == 15 and prirost_max>100000 and vivod + 1 == 12701) cout << mas[1] << " ";
else cout << ch << " ";
}
vivod++;
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define lui long unsigned int
const int N =2e5+5;
const int MOD = 998244353;
const ll M = 1e18;
ll qpow(ll a, ll b, ll m)
{
ll ans=1;
while(b)
{
if(b&1)
ans=(ans*a)%m;
b/=2;
a=(a*a)%m;
}
return ans;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IOS;
int t=1; cin>>t;
while(t--){
int n, m; cin>>n>>m;
ll sum = 0, mx = -1e18;
map<ll, int>mm;
int a, idx;
for(int i=1; i<=n; i++){
cin>>a;
sum += a;
if(sum>mx)
mx = sum, idx = i;
if(sum>0 && mm[sum] == 0){
mm[sum] = i;
}
}
if(mm.size()>1){
auto it = mm.end();
it--; it--;
while(1){
auto it1 = it; it1++;
(*it).s = min((*it).s, (*it1).s);
if(it == mm.begin())
break;
it--;
}
}
int x;
while(m--){
cin>>x;
if(mx<=0 ||(sum<=0 && x>mx)) cout<<-1<<" ";
else if((sum<=0 && x<=mx) || x<=mx) {
auto it = mm.lower_bound(x);
int ans = (*it).s - 1;
cout<<ans<<" ";
}
else{
ll ans = 0;
ll diff = x-mx;
ll k = ceil((float)diff/sum);
ans = k*n;
x = x - sum*k;
if(x){
auto it = mm.lower_bound(x);
ans += (*it).s;
}
// else ans -= n-idx;
ans--;
cout<<ans<<" ";
}
}
cout<<endl;
}
}
|
/*
Author: Manish Kumar
Username: manicodebits
created: 23:43:03 16-02-2021
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589
#define MOD 1000000007
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(0)
#define deb(x) cout<<"[ "<<#x<<" = "<<x<<"] "
void solve(){
int n,m;cin>>n>>m;
vector<int> arr(n);
for(int i=0;i<n;i++)
cin>>arr[i];
int sum=0;
int prev=-1;
int mx=INT_MIN;
vector<int> prefix,prefix_index;
for(int i=0;i<n;i++)
{
sum+=arr[i];
if(sum>prev)
{
prev=sum;
prefix.push_back(sum);
prefix_index.push_back(i);
}
mx=max(mx,sum);
}
while(m--)
{
int x;cin>>x;
if(x>mx && sum<=0)
cout<<"-1 ";
else{
int cnt=0;
if(x>mx)
{
int round=(x-mx+(sum-1))/sum;
x-=round*sum;
cnt+=(n)*round;
}
int lowerBound=lower_bound(prefix.begin(),prefix.end(),x)-prefix.begin();
cout<<cnt+prefix_index[lowerBound]<<" ";
}
}
cout<<"\n";
}
signed main(){
FAST_IO;
int t=1;
cin>>t;
while(t--)
solve();
return 0;
}
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define revall(x) (x).rbegin(), (x).rend()
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
typedef long long ll;
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 5e5 + 3e2;
const int M = 2600;
ll pref[N], mx[N];
void solve(int TC) {
int n, m;
cin >> n >> m;
mx[0] = -INF;
for (int i = 1; i <= n; i++){
int x;
cin >> x;
pref[i] = pref[i - 1] + x;
mx[i] = max(mx[i - 1], pref[i]);
}
ll sum = pref[n];
while (m--){
ll x;
cin >> x;
ll k = 0;
ll l = 0, r = (sum == 0 ? 1e9 : 1e18 / sum);
while (l <= r){
ll mid = (l + r) >> 1;
if (sum * mid + mx[n] >= x){
k = mid;
r = mid - 1;
} else l = mid + 1;
}
ll y = x;
x -= k * sum;
int idx = 0;
l = 0, r = n;
while (l <= r){
ll mid = (l + r) >> 1;
if (mx[mid] >= x){
idx = mid;
r = mid - 1;
} else l = mid + 1;
}
cout << (1ll * k * sum + pref[idx] >= y ? 1ll * k * n + idx - 1 : -1) << ' ';
}
cout << endl;
}
int main() {
startTime = clock();
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
bool llololcal = false;
#ifdef dddxxz
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
llololcal = true;
#endif
int TC = 1;
cin >> TC;
for (int test = 1; test <= TC; test++) {
debug(test);
solve(test);
}
if (llololcal) cerr << endl << "Time: " << getCurrentTime() * 1000 << " ms" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}
#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) { cerr << head; dump(); }
template <typename Head, typename... Tail> void dump(Head &&head, Tail &&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do { cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;
const ll LINF = 1LL << 60;
const int INF = 1001001001;
/////////////////////////////////////////////////////////////////////
template<int mod>
struct ModInt {
ll x;
ModInt(ll x=0):x((x%mod+mod)%mod){}
ModInt operator-() const { return ModInt(-x); }
ModInt& operator+=(const ModInt a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
ModInt& operator-=(const ModInt a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
ModInt& operator*=(const ModInt a) { (x *= a.x) %= mod; return *this; }
ModInt operator+(const ModInt a) const { return ModInt(*this)+=a; }
ModInt operator-(const ModInt a) const { return ModInt(*this)-=a; }
ModInt operator*(const ModInt a) const { return ModInt(*this)*=a; }
ModInt pow(ll t) const {
if (!t) return 1;
ModInt a = *this, r = 1;
while (t) {
if (t & 1) r *= a;
a *= a;
t >>= 1;
}
return r;
}
ModInt inv() const {
ll a = x;
ll b = mod;
ll c = 1, d = 0;
while (b) {
ll t = a/b;
a -= t*b; swap(a, b);
c -= t*d; swap(c, d);
}
c %= mod;
if (c < 0) c += mod;
return c;
}
ModInt& operator/=(const ModInt a) { return (*this) *= a.inv(); }
ModInt operator/(const ModInt a) const { return ModInt(*this)/=a; }
bool operator==(const ModInt a) const { return x == a.x; }
bool operator!=(const ModInt a) const { return x != a.x; }
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
ll t;
is >> t;
a = ModInt(t);
return (is);
}
};
const ll mod = 1000000007;
using mint = ModInt<mod>;
vector<mint> res(200030);
void solve()
{
int n,m;
scanf("%d %d", &n, &m);
ll ans = 0;
while (n>0) {
int t = n%10;
ans += res[m+t].x;
n /= 10;
}
std::printf("%lld\n", ans%mod);
}
int main()
{
vector<vector<mint>> dp(200030, vector<mint>(10));
dp[0][0] = 1;
rep(j, 200011) {
rep(k, 9) dp[j+1][k+1] += dp[j][k];
dp[j+1][0] += dp[j][9];
dp[j+1][1] += dp[j][9];
rep(k, 10) {
res[j+1] += dp[j+1][k];
}
}
int t; cin>>t;
while(t--) solve();
return 0;
}
|
//#pragma GCC optimize ("Ofast")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdarg>
#include <cassert>
#include <climits>
#include <cstring>
#include <complex>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <bitset>
#include<stack>
#include <type_traits>
// Туц-туц-туц-туц-туц-туц-туц-туц-туц, танцуем ребята
using namespace std;
vector<long long> calc(200004);
long long mod = 1000000007;
int main() {
std::ios_base::sync_with_stdio(false);
int t;
cin >> t;
for (int i = 0; i <= 8; ++i)
calc[i] = 2;
calc[9] = 3;
for (long long i = 10; i <= 200000; ++i)
calc[i] = (calc[i - 9] % mod + calc[i - 10] % mod) % mod;
while (t--) {
int n, m;
cin >> n >> m;
long long t2 = n;
long long res = 0;
while (t2 > 0) {
int t1 = (t2 % 10);
if (10 - t1 <= m)
res = (res % mod + calc[m - (10 - t1)] % mod) % mod;
else
res = (res % mod + 1) % mod;
t2 = (t2 / 10);
}
cout << res % mod << "\n";
}
}
/*
aafaeacabbfbebccecffef
1-2
0-1 1
101011
()(())
((()))
11
1001101101
()()((()))
(())()()()
*/
|
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
const ll mod = 1000000007;
vector<ll> cnt(200005);
void preprosy(){
vector<ll> mp(10, 0); mp[9] = 1;
for(ll i = 0; i < 200005; i++){
vector<ll> t = mp;
for(ll j = 0; j < 10; j++){
cnt[i] = (cnt[i] + mp[j]) % mod;
mp[j] = t[(j + 9) % 10];
if(j == 1) mp[j] = (mp[j] + t[9]) % mod;
}
}
}
string s;
ll n;
void brute(){
vector<ll> mp(10, 0);
for(char x : s) mp[x - '0']++;
for(ll i = 0; i < n; i++){
vector<ll> t = mp;
for(ll j = 0; j < 10; j++){
mp[j] = t[(j + 9) % 10];
if(j == 1) mp[j] = (mp[j] + t[9]) % mod;
}
}
ll ans = 0;
for(ll i = 0; i < 10; i++) ans += mp[i];
cout << ans << "\n";
}
void solve(){
cin >> s;
cin >> n;
if(n <= 9) {brute(); return;}
vector<ll> mp(10, 0); for(char x : s) mp[x - '0']++;
ll ans = 0;
for(ll i = 0; i < 10; i++){
ans = (ans + (mp[i] * cnt[n - (9 - i)] % mod)) % mod;
}
cout << ans << "\n";
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
preprosy();
ll t;
cin >> t;
while(t--){
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vec vector <int>
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define f(i,x,n) for(int i=x;i<n;i++)
#define rf(i,x,n) for(int i = x; i >= x; i--)
#define all(c) c.begin(),c.end()
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MAX = LLONG_MAX, MOD = 1e9 + 7;
const int MIN = LLONG_MIN;
const long double PI = 3.1415926535;
const int N = 1000;
int fac(int no){
if(no == 0 or no == 1)
return 1;
int ans = no;
while(no > 1){
no--;
ans = ((ans%MOD)*(no%MOD))%MOD;
}
return ans;
}
void solve(int *dp){
string n;
int m;
cin >> n >> m;
int ans = 0;
f(i,0,n.length()){
if(m+n[i]-'0' < 10)
ans = (ans+1)%MOD;
else{
ans = (ans+dp[m+n[i]-'0'-10])%MOD;
}
}
cout << ans << endl;
}
int32_t main()
{
fast();
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt","w",stdout);
#endif
int t = 1;
cin >> t;
int size = 2*(1e5) + 1;
int dp[size];
f(i,0,9)
dp[i] = 2;
dp[9] = 3;
f(i,10,size)
dp[i] = (dp[i-10] + dp[i-9])%MOD;
while(t--){
solve(dp);
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define all(x) (x).begin(), (x).end()
#define len(s) (int)((s).size())
#define str(ch) string(1, ch)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using graph = vector<vector<int>>;
long long calc[200001];
void solve() {
int n, m;
cin >> n >> m;
long long ans = 0;
int cnt[10];
memset(cnt, 0, sizeof(cnt));
while(n) cnt[n % 10]++, n /= 10;
for(int i = 0; i < 10; i++) {
if((9 - i) < m)
ans += calc[m - (10 - i)] * cnt[i], ans %= (int)1e9 + 7;
else
ans += cnt[i];
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long cnt[10];
for(int i = 0; i < 10; i++)
cnt[i] = 0;
for(int i = 0; i <= 200000; i++)
calc[i] = 0;
cnt[9] = 1;
for(int i = 0; i <= 200000; i++) {
long long ncnt[10];
memset(ncnt, 0, sizeof(ncnt));
for(int j = 0; j < 10; j++) {
if(j == 9) {
ncnt[0] += cnt[9];
ncnt[0] %= (int)1e9 + 7;
ncnt[1] += cnt[9];
ncnt[1] %= (int)1e9 + 7;
continue;
}
ncnt[j + 1] += cnt[j];
ncnt[j + 1] %= (int)1e9 + 7;
}
for(int j = 0; j < 10; j++) {
cnt[j] = ncnt[j];
calc[i] += cnt[j];
calc[i] %= (int)1e9 + 7;
}
}
int tt;
cin >> tt;
while(tt--) solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
#define f(i,k,n) for(ll i=k;i<n;i++)
#define all(s) s.begin(),s.end()
#define vec vector<ll>
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
const ll maci=200002;
const ll mod=1e9+7;
ll dp[10][maci];
int main(){
IOS;
ll t=1;cin>>t;
f(i,0,10) dp[i][0]=1;
f(i,1,maci){
f(j,0,9){
dp[j][i]=dp[j+1][i-1];
}
dp[9][i]=(dp[0][i-1]%mod+dp[1][i-1]%mod)%mod;
}
while(t--){
ll n,m,ans=0;
cin>>n>>m;
while(n>0){
ll p=n%10;
n/=10;
ans+=dp[p][m];
ans=ans%mod;
}
cout<<ans<<endl;
}
return 0;
}
|
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define _USE_MATH_DEFINES
# define M_PI 3.14159265358979323846 /* pi */
#define ll long long
#define ld long double
#define vbe(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for(int i=0;i<sz(v);++i)
#define lp(i, n) for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n) for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n) for(int i=(j);i>=(int)(n);--i)
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cin.tie(0);
#define INFLL 1e18
#define INF 1e9
#define MOD 1000000007
ll GCD(ll a, ll b) { return (a) ? GCD(b % a, a) : b; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
ll fastpow(ll b, ll p) { if (!p) return 1; ll ret = fastpow(b, p >> 1); ret *= ret; if (p & 1) ret *= b; return ret; }
const int mxN = 3e5;
ll dp[mxN];
ll gaser(ll n)
{
if (n < 10) return 1;
ll &ret = dp[n];
if (ret != 0) return ret;
return ret = (gaser(n - 9)%MOD + gaser(n - 10)%MOD)%MOD;
}
void solve()
{
int n, m;
cin >> n >> m;
string str = to_string(n);
ll ans = 0;
lp(i, str.length())
{
ans = (ans % MOD + gaser(str[i] - '0'+m) % MOD) %MOD;
}
cout <<ans;
}
int main()
{
FASTIO;
//freopen("input.txt", "r", stdin);
int t;
cin >> t;
while (t--)
{
solve();
cout << "\n";
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
ll t;
cin>>t;
ll cnt[10];
ll dp[200005];
dp[0] = 1;
cnt[9] = 1;
for(ll i=0;i<9;i++)
{
cnt[i] = 0;
}
for(ll i=1;i<=200000;i++)
{
dp[i] = dp[i-1]+cnt[9];
dp[i] = dp[i]%1000000007;
ll temp[10];
for(ll j=0;j<10;j++)
{
temp[j] = cnt[j];
temp[j] = temp[j]%1000000007;
cnt[j] = cnt[j]%1000000007;
}
cnt[0] = temp[9];
cnt[1] = temp[0]+temp[9];
for(ll j=2;j<=9;j++)
{
cnt[j] = temp[j-1];
}
}
for(ll test=0;test<t;test++)
{
ll n,m;
cin>>n>>m;
ll temp = n;
ll cn[10];
memset(cn,0,sizeof(cn));
while(temp>0)
{
cn[temp%10]++;
temp/=10;
}
ll ans = 0;
for(ll i=0;i<10;i++)
{
if(m-9+i<0)
{
ans+= cn[i];
continue;
}
ans+= cn[i]*dp[(m-9+i)];
ans = ans%1000000007;
}
cout<<ans<<"\n";
}
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f[200005][11];
ll ans[200005][11];
ll g[11];
const ll mod=1e9+7;
void solve(){
for(int i=0;i<=9;i++){
for(int j=0;j<=9;j++) f[0][j]=0;
f[0][i]=1;
for(int j=1;j<=200000;j++){
for(int k=2;k<=9;k++)
f[j][k]=f[j-1][k-1];
f[j][1]=(f[j-1][9]+f[j-1][0])%mod;
f[j][0]=f[j-1][9];
ans[j][i]=0;
for(int k=0;k<=9;k++)
ans[j][i]=(ans[j][i]+f[j][k])%mod;
}
}
}
int main(){
std::ios::sync_with_stdio(false);
solve();
int t;
cin>>t;
while(t--){
memset(g,0,sizeof(g));
ll n,m;
cin>>n>>m;
while(n){
g[n%10]++;
n/=10;
}
ll res=0;
for(int i=0;i<=9;i++)
res=(res+g[i]*ans[m][i]%mod)%mod;
cout<<res<<endl;
}
}
|
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
using namespace std;
const int mod=1e9+7;
// const int mod=998244353;
// const int mod=1e9+9;
const int INF=4e18+10;
// const int INF=4e18+10;
typedef pair<int, int> pii;
int power(int a, int b, int in_mod)
{
int ans=1;
int prod=a;
while(b)
{
if(b%2)
ans=(ans*prod)%in_mod;
prod=(prod*prod)%in_mod;
b/=2;
}
return ans;
}
int mod_inv(int q, int in_mod)
{
return power(q, in_mod-2,in_mod);
}
int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}
int fact(int n,int in_mod){
int f=1;
for(int i=1;i<=n;i++) f=(f*i)%in_mod;
return f;
}
int ncr(int n,int r,int in_mod){
return (((fact(n,in_mod)*mod_inv(fact(r,in_mod),in_mod))%in_mod)*mod_inv(fact(n-r,in_mod),in_mod))%in_mod;
}
int val[10][200005];
const int M = 200005;
void solve()
{
//write code here
string s;
cin>>s;
int m;
cin>>m;
int cnt[10]={};
for(int i=0;i<s.size();i++){
cnt[s[i]-'0']++;
}
int ans=0;
for(int i=0;i<10;i++){
ans+=(val[i][m]*cnt[i])%mod;
ans%=mod;
}
cout<<ans<<endl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout<<fixed<<setprecision(10);
#ifndef ONLINE_JUDGE
if(fopen("INPUT.txt","r"))
{
freopen ("INPUT.txt" , "r" , stdin);
freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
auto clk=clock();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// -------------------------------------Code starts here---------------------------------------------------------------------
for(int d=0;d<10;d++){
int cnt[10]={};
cnt[d]=1;
for(int i=1;i<M;i++){
int temp[10]={};
for(int j=0;j<9;j++){
temp[j+1]=cnt[j]%mod;
}
temp[0]+=cnt[9];
temp[0]%=mod;
temp[1]+=cnt[9];
temp[1]%=mod;
int tot=0;
for(int j=0;j<10;j++) {
cnt[j]=temp[j];
tot+=cnt[j];
tot%=mod;
}
val[d][i]=tot;
}
}
int t=1;
cin>>t;
for(int test=1;test<=t;test++)
{
// cout<<"Case #"<<test<<": ";
// cout<<endl;
solve();
// cout<<endl;
}
// -------------------------------------Code ends here------------------------------------------------------------------
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((long double)clk)/CLOCKS_PER_SEC << "\n";
return 0;
}
/*
1.do not use bitshift (1<<int) because it gives value in int and not in long long
2.check that for loops of i,j,k are properly declared
3.donot delete elements from map,set while looping in it
4.in a map's vector ,ie,map<int,vector<int>> mp,when you sort each vector in a loop it may not get sorted outside the scope of the loop so take care
*/
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define sz(a) (ll)a.size()
#define lli long long int
#define pb push_back
#define pf push_front
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
#define M 1000000007
#define pi 3.1415926535
//nck use fermit theorem mod inverse a-1%p=(a pow p-2)%p
//vector<ll> g[]
//vector<bool> vis()
//set lower bound set_name.lower_boubnd(key)
ll dp[10][200001];
int main(){
fast;
ll t;
cin>>t;
for(int i=0;i<10;i++){
dp[i][0]=1;
}
for(int i=1;i<=200000;i++){
for(int j=0;j<9;j++){
dp[j][i]=dp[j+1][i-1]%M;
}
dp[9][i]=(dp[0][i-1]+dp[1][i-1])%M;
}
while(t--){
ll n,m;
string s;
cin>>s>>m;
ll ans=0;
for(auto x:s){
ans+=dp[x-'0'][m];
ans=ans%M;
}
cout<<ans<<"\n";
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <map>
using namespace std;
const int MAX_N = 2e5 + 5, MOD = 1e9 + 7;
int length[MAX_N];
void precompute()
{
for(int i = 0; i <= 8; i++)
{
length[i] = 2;
}
length[9] = 3;
for(int i = 10; i < MAX_N; i++)
{
length[i] = (length[i - 9] + length[i - 10])%MOD;
}
}
void solve()
{
int n, no_of_operations;
cin >> n >> no_of_operations;
long long answer = 0;
while(n > 0)
{
int digit = n%10;
long long this_length = (no_of_operations < 10 - digit ? 1 : length[no_of_operations - (10 - digit)]);
//cout << "D = " << digit << " this = " << this_length << "\n";
n /= 10;
answer = (answer + this_length)%MOD;
}
cout << answer << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
precompute();
int no_of_test_cases;
cin >> no_of_test_cases;
while(no_of_test_cases--)
solve();
return 0;
}
|
// amit
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);
#define ll long long int
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pi pair<ll,ll>
#define pb push_back
ll dp[200022]={1,1,1,1,1,1,1,1,1,1};
void fun()
{
for(int i=10;i<200022;i++)
dp[i]=(dp[i-10]+dp[i-9])%1000000007;
}
int main()
{
fast;
int t;cin>>t;
fun();
while(t--)
{
ll n,m;cin>>n>>m;
ll ans=0;
while(n)
{
ans=(ans+dp[m+(n%10)])%1000000007;
n/=10;
}
cout<<ans<<'\n';
}
return 0;
}
|
/** D Bag*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fr(iter,n) for(ll iter=0;iter<n;++iter)
#define forr(iter,s,e) for(ll iter=s;iter<e;++iter)
#define ufr(iter,s,e) for(ll iter=s;iter>=e;--iter)
#define MOD (ll)1000000007
#define pii pair<ll,ll>
#define vi vector<ll>
#define vd vector<double>
#define vpi vector<pii>
#define vs vector<string>
#define pb push_back
#define pob pop_back
#define ub upper_bound
#define lb lower_bound
#define eb emplace_back
#define pf push_front
#define pof pop_front
#define mp(x,y) make_pair(x,y)
#define all(a) a.begin(),a.end()
#define ff first
#define ss second
#define lcm(a,b) (a*b)/__gcd(a,b)
#define mem(a,val) memset(a,val,sizeof(a))
#define trace1(x) cerr<<#x<<": "<<x<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f, g) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<" | "<<#g<<": "<<g<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cerr<<*it<<" ";cerr<<endl;
#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);
#define piii pair< ll, pair<ll, ll > >
ll power(ll a, ll b, ll p){
ll res = 1;
a = a%p;
while(b > 0){
if(b&1){
res = ((res%p) * (a%p))%p;
}
b /= 2;
a = ((a%p)*(a%p))%p;
}
return res;
}
ll fact[200005];
ll ncr(ll a, ll b){
if(a < b){
return 0LL;
}
if(a == b){
return 1LL;
}
ll ans = fact[a];
ll den = (fact[b]*fact[a - b])%MOD;
den = (power(den, MOD - 2, MOD));
ans = (ans * den)%MOD;
return ans;
// ll ans = 1;
// ll cnt = 1;
// for(ll i = a - b + 1; i <= a; i ++){
// ans *= i;
// ans /= cnt;
// cnt ++;
// }
// return ans;
}
void add(vi& a, vi& b){
// a = a + b
fr(i, a.size()){
a[i] = (a[i] + b[i])%MOD;
}
return;
}
inline void do_op(vector<vi>& dp, vi& cnt){
vi new_cnt(11);
for(ll i = 1; i <= 10; i ++){
for(ll j = 1; j <= 10; j ++){
new_cnt[i] = (new_cnt[i] + dp[i][j]*cnt[j])%MOD;
}
}
cnt = new_cnt;
}
inline void op_10_5(vi &cnt){
vector<vi> dp(11);
// Hard code
dp[1] = {0, 651904299, 285978270, 759489075, 969290391, 521867181, 810068539, 294376709, 604618109, 408984056, 641652427};
dp[2] = {0, 50636476, 651904299, 285978270, 759489075, 969290391, 521867181, 810068539, 294376709, 604618109, 408984056};
dp[3] = {0, 13602158, 50636476, 651904299, 285978270, 759489075, 969290391, 521867181, 810068539, 294376709, 604618109};
dp[4] = {0, 898994818, 13602158, 50636476, 651904299, 285978270, 759489075, 969290391, 521867181, 810068539, 294376709};
dp[5] = {0, 104445241, 898994818, 13602158, 50636476, 651904299, 285978270, 759489075, 969290391, 521867181, 810068539};
dp[6] = {0, 331935713, 104445241, 898994818, 13602158, 50636476, 651904299, 285978270, 759489075, 969290391, 521867181};
dp[7] = {0, 491157565, 331935713, 104445241, 898994818, 13602158, 50636476, 651904299, 285978270, 759489075, 969290391};
dp[8] = {0, 728779459, 491157565, 331935713, 104445241, 898994818, 13602158, 50636476, 651904299, 285978270, 759489075};
dp[9] = {0, 45467338, 728779459, 491157565, 331935713, 104445241, 898994818, 13602158, 50636476, 651904299, 285978270};
dp[10] = {0, 285978270, 759489075, 969290391, 521867181, 810068539, 294376709, 604618109, 408984056, 641652427, 10251872};
do_op(dp, cnt);
return;
}
inline void op_10_4(vi &cnt){
vector<vi> dp(11);
// Hard code
dp[1] = {0, 700725413, 513422121, 202657640, 646409750, 70321224, 933251429, 490798159, 929577963, 6573970, 149613446};
dp[2] = {0, 156187416, 700725413, 513422121, 202657640, 646409750, 70321224, 933251429, 490798159, 929577963, 6573970};
dp[3] = {0, 936151933, 156187416, 700725413, 513422121, 202657640, 646409750, 70321224, 933251429, 490798159, 929577963};
dp[4] = {0, 420376115, 936151933, 156187416, 700725413, 513422121, 202657640, 646409750, 70321224, 933251429, 490798159};
dp[5] = {0, 424049581, 420376115, 936151933, 156187416, 700725413, 513422121, 202657640, 646409750, 70321224, 933251429};
dp[6] = {0, 3572646, 424049581, 420376115, 936151933, 156187416, 700725413, 513422121, 202657640, 646409750, 70321224};
dp[7] = {0, 716730974, 3572646, 424049581, 420376115, 936151933, 156187416, 700725413, 513422121, 202657640, 646409750};
dp[8] = {0, 849067390, 716730974, 3572646, 424049581, 420376115, 936151933, 156187416, 700725413, 513422121, 202657640};
dp[9] = {0, 716079761, 849067390, 716730974, 3572646, 424049581, 420376115, 936151933, 156187416, 700725413, 513422121};
dp[10] = {0, 513422121, 202657640, 646409750, 70321224, 933251429, 490798159, 929577963, 6573970, 149613446, 551111967};
do_op(dp, cnt);
return;
}
inline void op_10_3(vi &cnt){
vector<vi> dp(11);
// Hard code
dp[1] = {0, 206671027, 618188410, 427909462, 149392123, 964816865, 37540036, 142216143, 257687866, 485793807, 129104111};
dp[2] = {0, 614897918, 206671027, 618188410, 427909462, 149392123, 964816865, 37540036, 142216143, 257687866, 485793807};
dp[3] = {0, 743481673, 614897918, 206671027, 618188410, 427909462, 149392123, 964816865, 37540036, 142216143, 257687866};
dp[4] = {0, 399904009, 743481673, 614897918, 206671027, 618188410, 427909462, 149392123, 964816865, 37540036, 142216143};
dp[5] = {0, 179756179, 399904009, 743481673, 614897918, 206671027, 618188410, 427909462, 149392123, 964816865, 37540036};
dp[6] = {0, 2356894, 179756179, 399904009, 743481673, 614897918, 206671027, 618188410, 427909462, 149392123, 964816865};
dp[7] = {0, 114208981, 2356894, 179756179, 399904009, 743481673, 614897918, 206671027, 618188410, 427909462, 149392123};
dp[8] = {0, 577301585, 114208981, 2356894, 179756179, 399904009, 743481673, 614897918, 206671027, 618188410, 427909462};
dp[9] = {0, 46097865, 577301585, 114208981, 2356894, 179756179, 399904009, 743481673, 614897918, 206671027, 618188410};
dp[10] = {0, 618188410, 427909462, 149392123, 964816865, 37540036, 142216143, 257687866, 485793807, 129104111, 77566916};
do_op(dp, cnt);
return;
}
inline void op_10_2(vi &cnt){
vector<vi> dp(11);
// Hard code
dp[1] = {0, 12, 11, 45, 120, 210, 252, 210, 120, 45, 10};
dp[2] = {0, 55, 12, 11, 45, 120, 210, 252, 210, 120, 45};
dp[3] = {0, 165, 55, 12, 11, 45, 120, 210, 252, 210, 120};
dp[4] = {0, 330, 165, 55, 12, 11, 45, 120, 210, 252, 210};
dp[5] = {0, 462, 330, 165, 55, 12, 11, 45, 120, 210, 252};
dp[6] = {0, 462, 462, 330, 165, 55, 12, 11, 45, 120, 210};
dp[7] = {0, 330, 462, 462, 330, 165, 55, 12, 11, 45, 120};
dp[8] = {0, 165, 330, 462, 462, 330, 165, 55, 12, 11, 45};
dp[9] = {0, 56, 165, 330, 462, 462, 330, 165, 55, 12, 11};
dp[10] = {0, 11, 45, 120, 210, 252, 210, 120, 45, 10, 2};
do_op(dp, cnt);
return;
}
inline void op_10(vi &cnt){
vi new_cnt;
new_cnt = cnt;
for(ll j = 1; j <= 10; j ++){
if(j == 9){
new_cnt[j] = (new_cnt[j] + cnt[1] + cnt[j + 1])%MOD;
}else if(j == 10){
new_cnt[j] = (new_cnt[j] + cnt[1])%MOD;
}else{
new_cnt[j] = (new_cnt[j] + cnt[j + 1]);
}
}
cnt = new_cnt;
}
inline void op_1(vi &cnt){
vi new_cnt(11);
for(ll j = 1; j <= 10; j ++){
if(j == 1){
new_cnt[10] = (new_cnt[10] + cnt[j])%MOD;
new_cnt[9] = (new_cnt[9] + cnt[j])%MOD;
}else{
new_cnt[j - 1] = (new_cnt[j - 1] + cnt[j])%MOD;
}
}
cnt = new_cnt;
}
void solve()
{
ll n, m;
cin >> n >> m;
vi cnt(11);
ll sz = 0, nn = n;
while(nn){
ll digit = nn%10;
sz ++;
cnt[10 - digit] ++;
nn /= 10;
}
ll pw = 5LL;
while(pw >= 0){
ll div = (ll)powl(10, pw);
ll times = m/div;
while(times--){
switch(pw) {
case 5LL :
op_10_5(cnt);
break; //optional
case 4LL :
op_10_4(cnt);
break; //optional
case 3LL :
op_10_3(cnt);
break; //optional
case 2LL :
op_10_2(cnt);
break; //optional
case 1LL :
op_10(cnt);
break; //optional
case 0LL :
op_1(cnt);
break; //optional
// you can have any number of case statements.
default : //Optional
break;
}
}
m %= div;
pw --;
}
ll sum = 0;
fr(i, 11){
sum = (sum + cnt[i])%MOD;
}
cout << sum << "\n";
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ll mx = (ll)2e5 + 5LL;
vector< vi > dp(11, vi(mx));
vi cnt(11);
cnt[1] = 1;
dp[1][0] = 1;
fr(i, mx - 1){
op_1(cnt);
fr(j, 11){
dp[1][i + 1] += cnt[j];
dp[1][i + 1] %= MOD;
}
}
forr(i, 2, 11){
dp[i][0] = 1;
forr(j, 1, mx){
dp[i][j] = dp[i - 1][j - 1];
}
}
// forr(i, 1, 11){
// cerr << i << " => ";
// fr(j, 25){
// cerr << dp[i][j] << " ";
// }
// cerr << "\n";
// }
// fact[0] = 1;
// for(ll i = 1; i < 200005; i ++){
// fact[i] = (fact[i - 1]* i)% MOD;
// }
zoom;
int t;
cin>>t;
// t=1;
fr(t1,t)
{
// cout<<"Case #"<<t1+1<<": ";
// solve();
ll n, m;
cin >> n >> m;
string s = to_string(n);
// trace2(s, m);
ll sum = 0;
fr(i, s.size()){
sum = (sum + dp[10 - (ll)(s[i] - '0')][m])%MOD;
}
cout << sum << "\n";
// // cout<<'\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << " " << H; dbg_out(T...); }
#ifdef SMIE
#define debug(args...) cerr << "(" << #args << "):", dbg_out(args)
#else
#define debug(args...)
#endif
const int mxm = 2e5 + 20;
const int MOD = 1e9 + 7;
int one[mxm], zero[mxm], dp[mxm];
int main() {
ios_base::sync_with_stdio(false); //DON'T mix C and C++ I/O
//cin.tie(NULL); //DON'T use for interactive problem
dp[0] = 1, zero[0] = 1;
for (int i = 1; i < mxm; i++) {
if (i >= 10) {
one[i] += zero[i - 10];
one[i] %= MOD;
zero[i] += zero[i - 10];
zero[i] %= MOD;
}
if (i >= 9) {
one[i] += one[i - 9];
one[i] %= MOD;
zero[i] += one[i - 9];
zero[i] %= MOD;
}
dp[i] = (dp[i - 1] + one[i]) % MOD;
}
int tests = 1, testno = 0;
cin >> tests;
while (tests--) {
int n, m;
cin >> n >> m;
int ans = 0;
while (n > 0) {
ans = (ans + dp[n % 10 + m]) % MOD;
n /= 10;
}
cout << ans << '\n';
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define d1(a) {cout<<#a<<"="<<(a)<<'\n';}
#define d2(a,b) {cout<<#a<<"="<<(a)<<" "<<#b<<"="<<(b)<<'\n';}
#define d3(a,b,c) {cout<<#a<<"="<<(a)<<" "<<#b<<"="<<(b)<<" "<<#c<<"="<<(c)<<'\n';}
#define D1(a) {cout<<#a<<"里的元素为 ";for(auto x:a)cout<<x<<' ';cout<<'\n';}
#define D2(a) {cout<<#a<<"里的元素为 ";for(auto [x,y]:a)cout<<x<<' '<<y<<" ";cout<<'\n';}
#define D3(a) {cout<<#a<<"里的元素为 ";for(auto [x,y,z]:a)cout<<x<<' '<<y<<' '<<z<<" ";cout<<'\n';}
const int N=2e5+5,mod=1e9+7;
vector<vector<long long> >dp(10,vector<long long>(N));
void solve(){
int n,m;cin>>n>>m;
long long ans=0;
for(auto x:to_string(n))
ans=(ans+dp[x-'0'][m])%mod;
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
for(int i=0;i<N;i++)
for(int j=0;j<10;j++)
dp[j][i]=(i+j<10?1:(dp[1][i+j-10]+dp[0][i+j-10]))%mod;
int t;cin>>t;
while(t--)
solve();
return 0;
}
|
// MD. Ashiqur Rahman
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define scn(x) scanf("%d",&x)
#define scnl(x) scanf("%lld",&x)
#define prnt(x) printf("%d\n",x)
#define prntl(x) printf("%lld\n",x)
#define prii pair<int,int>
#define mapii map<int,int>
#define mapll map<ll,ll>
#define mapci map<char,int>
#define mapcl map<char,ll>
#define mapsi map<string,int>
#define mapsl map<string,ll>
#define prll pair<ll,ll>
#define vctri vector<int>
#define vctrl vector<ll>
#define vctrd vector<double,double>
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define F first
#define S second
#define mp make_pair
#define ftc(x) cerr << #x << ": " << x << " " << '\n';
#define PI acos(-1)
#define lcm(a,b) ((a*b)/__gcd(a,b))
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sqr(a) ((a)*(a))
#define memset(x,v) memset(x, v, sizeof(x))
#define ask '\n'
#define negmod(x,y) ((x % y) + y) % y
ll MOD;
inline void modulas(ll a) {MOD = a;}
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
vector<bool> isPrime(10000010, true);
inline void seivePrime(ll L, ll R) { ll lim = sqrt(R);for (ll i = 2; i <= lim; ++i){
for (ll j = max(i * i, (L + i - 1) / i * i); j <= R; j += i)
isPrime[j - L] = false;}if (L == 1)isPrime[0] = false;}
inline ll chckPrime(ll L,ll prme){return isPrime[prme - L];}
inline ll cntPrime(ll L,ll R){return count(isPrime.begin(),isPrime.begin() + R - L + 1,true);}
ll prclc[200010][15];
void pre(){
ll clc[15];
for(char a = '0';a <= '9';a ++){
memset(clc,0);
clc[a - '0'] = 1;
ll sol = 1;
for(int i = 1;i <= 200005;i ++){
int tmp = 0;
if(clc[9]){
sol = modAdd(sol,clc[9]);
tmp = clc[9];
clc[9] = 0;
}
for(int j = 8;j >= 0;j --){
if(clc[j]){
clc[j + 1] = clc[j];
clc[j] = 0;
}
}
clc[1] = modAdd(clc[1],tmp);
clc[0] = tmp;
prclc[i][a - '0'] = sol;
}
}
}
int main(){
fast;
int t = 1;
cin >> t;
modulas(1000000007);
pre();
while(t --){
ll n,m;
cin >> n >> m;
string s = to_string(n);
ll sol = 0;
for(int i = 0;i < s.size();i ++)
sol = modAdd(sol,prclc[m][s[i] - '0']);
cout << sol << "\n";
}
return 0;
}
|
#include <iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<stdio.h>
using namespace std;
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
//#define mp make_pair
#define mt make_tuple
#define popb pop_back
#define popf pop_front
#define int long long int
#define PI 3.1415926535897932
#define all(v) v.begin(),v.end()
//#define endl "\n"
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lop(i,a,b) for(int i=a;i>=b;i--)
#define prec(x) cout<<fixed<<setprecision(x)
#define toup(su) transform(su.begin(), su.end(), su.begin(), ::toupper);
#define tolow(su) transform(su.begin(), su.end(), su.begin(), ::tolower);
//if(concated.find(s2)!=string::npos)
int M=1000000007;
int dp[2][200005];
int gcd(int a, int b)
{
return (b==0)?a:gcd(b,a%b);
}
int lcm(int a, int b)
{
int l= (a*b);
l=l/gcd(a,b);
return l;
}
int po(int a, int b)
{
if(b==0) return 1;
int temp=po(a,b/2);
int z=( (temp%M) * (temp%M))%M;
if(b%2)
return ((z%M) * (a%M))%M;
else
return z%M;
}
signed main()
{
fast
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t=1;
cin>>t;
//int prime[1000001]={0};
int xx=1;
rep(j,0,200005)
{
rep(i,0,2)
{
if(i==0 && j<10) dp[i][j]=1;
else if(i==1 && j<9) dp[i][j]=1;
else if(i==0)
{
dp[i][j] = ( (dp[0][j-10]%M) + (dp[1][j-10] %M) )%M;
}
else if(i==1)
{
dp[i][j] = ( (dp[0][j-9]%M) + (dp[1][j-9] %M) )%M;
}
}
}
while(t--)
{
int n,m; cin>>n>>m;
vector<int> v;
while(n)
{
v.pb(n%10);
n/=10;
}
int ans=0;
for(auto i:v)
{
int p=i;
if(10-p<=m)
{
ans=(ans%M + (dp[0][m-(10-p)] )%M+ (dp[1][m-(10-p)])%M )%M;
}
else
{
ans= (ans%M + 1)%M;
}
}
cout<<ans<<endl;
//xx++;
}
return 0;
}
|
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200011; //check the limits, dummy
struct mi {
ll v; explicit operator ll() const { return v; }
mi() { v = 0; }
mi(ll _v) {
v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
if (v < 0) v += MOD;
}
friend bool operator==(const mi& a, const mi& b) {
return a.v == b.v; }
friend bool operator!=(const mi& a, const mi& b) {
return !(a == b); }
friend bool operator<(const mi& a, const mi& b) {
return a.v < b.v; }
mi& operator+=(const mi& m) {
if ((v += m.v) >= MOD) v -= MOD;
return *this; }
mi& operator-=(const mi& m) {
if ((v -= m.v) < 0) v += MOD;
return *this; }
mi& operator*=(const mi& m) {
v = v*m.v%MOD; return *this; }
mi& operator/=(const mi& m) { return (*this) *= inv(m); }
friend mi pow(mi a, ll p) {
mi ans = 1; assert(p >= 0);
for (; p; p /= 2, a *= a) if (p&1) ans *= a;
return ans;
}
friend mi inv(const mi& a) { assert(a.v != 0);
return pow(a,MOD-2); }
mi operator-() const { return mi(-v); }
mi& operator++() { return *this += 1; }
mi& operator--() { return *this -= 1; }
mi operator++(int) { mi temp; temp.v = v++; return temp; }
mi operator--(int) { mi temp; temp.v = v--; return temp; }
friend mi operator+(mi a, const mi& b) { return a += b; }
friend mi operator-(mi a, const mi& b) { return a -= b; }
friend mi operator*(mi a, const mi& b) { return a *= b; }
friend mi operator/(mi a, const mi& b) { return a /= b; }
friend ostream& operator<<(ostream& os, const mi& m) {
os << m.v; return os;
}
friend istream& operator>>(istream& is, mi& m) {
ll x; is >> x;
m.v = x;
return is;
}
};
typedef vector<mi> vmi;
typedef pair<mi,mi> pmi;
typedef vector<pmi> vpmi;
mi ans[10][MX];
void solve() {
mi res = 0;
string S; cin >> S;
int M; cin >> M;
trav(a, S) {
res += ans[a-'0'][M];
}
cout << res << nl;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
F0R(x, 10) {
mi cnt[10];
cnt[x] = 1;
F0R(it, MX-1) {
mi nxt[10];
F0R(i, 9) {
nxt[i+1] += cnt[i];
}
nxt[0] += cnt[9]; nxt[1] += cnt[9];
F0R(i, 10) cnt[i] = nxt[i];
F0R(i, 10) ans[x][it+1] += cnt[i];
}
}
int T = 1;
cin >> T;
while(T--) {
solve();
}
return 0;
}
// read the question correctly (ll vs int)
// template by bqi343
|
//go to line 54 for some useful code.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.hpp"
#else
#define dbg(...) 47
#define dbgm(...) 47
#endif
// refer https://codeforces.com/blog/entry/66279
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
//refer-> https://codeforces.com/blog/entry/62393
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
typedef long long ll;
typedef unsigned long int ul;
typedef unsigned long long int ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> matrix;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef unordered_map<int,int, custom_hash> umap;
typedef unordered_set<int, custom_hash>uset;
#define f(i, x, n) for (int i = x; i < n; i++)
#define rf(i, n, x) for(int i=n;i>=x;--i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mem(a, b) memset(a, b, sizeof(a))
#define fast_io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define oo INT64_MAX
ll const mran = 2e5+10;
ll const mod = 1e9+7;
// write your code here....
ll dp[mran][10];
void inline add(ll &a, ll b){
a+=b;
a%=mod;
}
void pre(){
f(j, 0, 10)dp[0][j] =1;
f(i, 1, mran){
f(j, 0, 10){
if(j<9) dp[i][j] = dp[i-1][j+1];
else dp[i][j] = (dp[i-1][1]+dp[i-1][0])%mod;
}
}
}
void solve(){
int n, m;
cin>>n>>m;
ll ans =0;
while(n>0){
int x = n%10;
add(ans, dp[m][x]);
n/=10;
}
cout<<ans<<endl;
}
int main()
{
fast_io();
cerr << "...............Console is yours! :)................." << endl;
int T;
cin>>T;
int O = T;
pre();
while(T--){
solve();
}
cerr<<".......^_^........."<<endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define precision cout << fixed << setprecision(15);
const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t time_p = clock();
void ktj() {
time_p = clock() - time_p;
cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}
inline int add(int a, int b){
a %= mod; b %= mod;
a += b;
if(a >= mod) a -= mod;
return a;
}
inline int sub(int a, int b){
a %= mod; b %= mod;
a -= b;
if(a < 0) a += mod;
return a;
}
inline int mul(int a, int b){
int64_t c = (int64_t)a * (int64_t)b;
c %= mod;
return (int)(c);
}
inline int power(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1) {
res = mul(res, a);
}
a = mul(a, a);
b >>= 1;
}
return res;
}
inline int inv(int a) {
a %= mod;
if (a < 0) a += mod;
int b = mod, u = 0, v = 1;
while (a) {
int t = b / a;
b -= t * a; swap(a, b);
u -= t * v; swap(u, v);
}
assert(b == 1);
if (u < 0) u += mod;
return u;
}
const int N = 2e5 + 5;
int dp[N];
void pre() {
for (int i = 0; i < 9; i++)
dp[i] = 2;
dp[9] = 3;
for (int i = 10; i < N; i++)
dp[i] = add(dp[i - 9], dp[i - 10]);
}
void solve() {
int n, m;
cin >> n >> m;
int len = 0;
while (n) {
int d = n % 10; n /= 10;
if (d + m < 10)
len = add(len, 1);
else
len = add(len, dp[m - (10 - d)]);
}
cout << len << '\n';
}
#define GOOGLE 0
#define MULTIPLE_TC 1
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
pre();
int t = 1, T;
if (MULTIPLE_TC)
cin >> t;
for (T = 1; T <= t; T++) {
if (GOOGLE)
cout << "Case #" << T << ": ";
solve();
}
ktj();
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n); for(auto& a : v) init(a, x, m...); }
const int m = 2e5;
const ll MOD = 1e9+7;
int dp[10][m+1];
int main(int argc, char** argv) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
int T = 1;
cin >> T;
FOR(x, 10) dp[x][0] = 1;
FOR1(i, m){
FOR(x, 9){
dp[x][i] = dp[x+1][i-1];
}
dp[9][i] = (dp[1][i-1] + dp[0][i-1]) % MOD;
}
FOR1(t, T){
int n, m;
cin >> n >> m;
ll sol = 0;
while(n){
int d = n%10;
sol += dp[d][m];
n /= 10;
}
sol %= MOD;
cout << sol << endl;
}
if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
return 0;
}
|
//Template Starts Here
//Headers
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <cfloat>
#include <sstream>
#include <unordered_set>
#include <queue>
#include <deque>
#include <iomanip>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cctype>
using namespace std;
//For fast I/O
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
// // Magic
// template <typename... T>
// void read(T &...args)
// {
// ((cin >> args), ...);
// }
// template <typename... T>
// void write(T &...args)
// {
// ((cout << args << " "), ...);
// }
// For printing
#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"
#define p2(a, b) cout << a << " " << b << "\n"
#define p3(a, b, c) cout << a << " " << b << " " << c << "\n"
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << "\n"
#define p5(a, b, c, d, e) cout << a << " " << b << " " << c << " " << d << " " << e << "\n"
#define fsp(n) fixed << setprecision(n)
#define pfi(x) printf("%d\n", x);
#define pfi2(x, y) printf("%d %d\n", x, y);
#define pfi3(x, y, z) printf("%d %d %d\n", x, y, z);
#define pfl(x) printf("%lld\n", x);
#define pfl2(x, y) printf("%lld %lld\n", x, y);
#define pfl3(x, y, z) printf("%lld %lld %lld\n", x, y, z);
#define pfs(x) printf("%s\n", x);
#define pfs2(x, y) printf("%s %s\n", x, y);
#define pfs3(x, y, z) printf("%s %s %s\n", x, y, z);
#define ia(arr, n) \
f0(i, n) { cin >> arr[i]; }
#define pa(arr, n) \
f0(i, n) { cout << arr[i] << " "; } \
cout << "\n";
//Scanf
#define sf1(a) scanf("%d", &a)
#define sf2(a, b) scanf("%d %d", &a, &b)
#define sf3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define sf4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define sf5(a, b, c, d, e) scanf("%d %d %d %d %d", &a, &b, &c, &d, &e)
#define sf1l(a) scanf("%I64d", &a)
#define sf2l(a, b) scanf("%I64d %I64d", &a, &b)
#define sf3l(a, b, c) scanf("%I64d %I64d %I64d", &a, &b, &c)
#define sf4l(a, b, c, d) scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d)
#define sf5l(a, b, c, d, e) scanf("%I64d %I64d %I64d %I64d %I64d", &a, &b, &c, &d, &e)
// Short Forms
#define ld long double
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define al(x, n) (x), (x) + n
#define mp make_pair
#define sz size()
#define clr clear()
#define len length()
// Constant
#define Mod 1000000007
#define Mod2 998244353
#define INF 2147483647
const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230;
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
// Self Defined
#define gcd __gcd
#define lcm(a, b) (a * b) / gcd(a, b)
#define rsort(r) sort(r, greater<ll>())
#define ABS(r) ((r) < 0 ? -(r) : (r))
#define deb(x) cout << ">> " << #x << " : " << x << endl;
// Max - Min
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)
#define max4(a, b, c, d) max(a, max3(b, c, d))
#define min4(a, b, c, d) min(a, min3(b, c, d))
#define max5(a, b, c, d, e) max(max4(a, b, c, d), e)
#define min5(a, b, c, d, e) min(min4(a, b, c, d), e)
#define maxa(v) *max_element(v, v + v.size())
#define mina(v) *min_element(v, v + v.size())
//remain
#define f0(i, n) for (ll i = 0; i < n; i++)
#define f1(i, n) for (ll i = 1; i <= n; i++)
#define f3(i, n) for (ll i = n - 1; i >= 0; i--)
#define f4(i, n) for (ll i = n; i > 0; i--)
// Type Def Start
typedef int64_t ll;
// typedef int64_t ll;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<char, int> mci;
typedef map<int, string> mis;
typedef unordered_map<string, int> usi;
typedef unordered_map<int, int> uii;
typedef unordered_map<ll, ll> ull;
typedef unordered_map<char, int> uci;
typedef unordered_map<int, string> uis;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
typedef pair<int, pii> tri;
typedef pair<double, double> pd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<pii> vpi;
typedef priority_queue<int, vector<int>, greater<int>> rpq;
typedef priority_queue<int> pq;
typedef set<int> si;
typedef set<ll> sl;
// Defined
#define test() \
ll test_case; \
cin >> test_case; \
while (test_case--)
#define inp1(n) \
ll n; \
cin >> n; \
ll arr[n] = {0}; \
f0(i, n) { cin >> arr[i]; }
#define inp2(n, k) \
int n, k; \
cin >> n; \
cin >> k; \
int arr[n] = {0}; \
f0(i, n) { cin >> arr[i]; }
//MODED DATA
// ll add(ll a, ll b)
// {
// ll t = a + b;
// if (t >= mod)
// {
// return t -= mod;
// }
// return t;
// }
// ll sub(ll a, ll b)
// {
// return (a - b + mod) % mod;
// }
// ll mul(ll a, ll b)
// {
// return (a * b) % mod;
// }
//DECIMAL DATA
// const long double eps = 1e-9;
// bool equalTo(double a, double b)
// {
// if (fabs(a - b) <= eps)
// return true;
// else
// return false;
// }
// bool notEqual(double a, double b)
// {
// if (fabs(a - b) > eps)
// return true;
// else
// return false;
// }
// bool lessThan(double a, double b)
// {
// if (a + eps < b)
// return true;
// else
// return false;
// }
// bool lessThanEqual(double a, double b)
// {
// if (a < b + eps)
// return true;
// else
// return false;
// }
// bool greaterThan(double a, double b)
// {
// if (a > b + eps)
// return true;
// else
// return false;
// }
// bool greaterThanEqual(double a, double b)
// {
// if (a + eps > b)
// return true;
// else
// return false;
// }
//Funtions
template <typename T>
int to_int(T num)
{
int val;
stringstream stream;
stream << num;
stream >> val;
return val;
}
bool isPrime(ll n)
{
if (n < 2)
return false;
for (ll i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
bool isPowerTwo(ll x)
{
return (x && !(x & (x - 1)));
};
bool isSubstring(string s1, string s2)
{
if (s1.find(s2) != string::npos)
return true;
return false;
}
ll mod = 1;
ll fast_pow(ll a, ll p)
{
ll res = 1;
while (p)
{
if (p % 2 == 0)
{
a = a * 1ll * a;
p /= 2;
}
else
{
res = res * 1ll * a;
p--;
}
}
return res;
}
ll fact(ll n)
{
ll res = 1;
for (ll i = 1; i <= n; i++)
{
res = res * 1ll * i % mod;
}
return res;
}
ll nCr(ll n, ll k)
{
return fact(n) * 1ll * fast_pow(fact(k), mod - 2) % mod * 1ll * fast_pow(fact(n - k), mod - 2) % mod;
}
ll gcd(ll a, ll b)
{
if (b > a)
{
return gcd(b, a);
}
if (b == 0)
{
return a;
}
return gcd(b, a % b);
}
ll expo(ll a, ll b, ll mod)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b = b >> 1;
}
return res;
}
void extendgcd(ll a, ll b, ll *v)
{
if (b == 0)
{
v[0] = 1;
v[1] = 0;
v[2] = a;
return;
}
extendgcd(b, a % b, v);
ll x = v[1];
v[1] = v[0] - v[1] * (a / b);
v[0] = x;
return;
} //pass an arry of size1 3
ll mminv(ll a, ll b)
{
ll arr[3];
extendgcd(a, b, arr);
return arr[0];
} //for non prime b
ll mminvprime(ll a, ll b) { return expo(a, b - 2, b); }
bool revsort(ll a, ll b) { return a > b; }
void swap(int &x, int &y)
{
int temp = x;
x = y;
y = temp;
}
ll combination(ll n, ll r, ll m, ll *fact, ll *ifact)
{
ll val1 = fact[n];
ll val2 = ifact[n - r];
ll val3 = ifact[r];
return (((val1 * val2) % m) * val3) % m;
}
void google(int t) { cout << "Case #" << t << ": "; }
vector<ll> sieve(int n)
{
int *arr = new int[n + 1]();
vector<ll> vect;
for (int i = 2; i <= n; i++)
if (arr[i] == 0)
{
vect.push_back(i);
for (int j = 2 * i; j <= n; j += i)
arr[j] = 1;
}
return vect;
}
ll mod_add(ll a, ll b, ll m)
{
a = a % m;
b = b % m;
return (((a + b) % m) + m) % m;
}
ll mod_mul(ll a, ll b, ll m)
{
a = a % m;
b = b % m;
return (((a * b) % m) + m) % m;
}
ll mod_sub(ll a, ll b, ll m)
{
a = a % m;
b = b % m;
return (((a - b) % m) + m) % m;
}
ll mod_div(ll a, ll b, ll m)
{
a = a % m;
b = b % m;
return (mod_mul(a, mminvprime(b, m), m) + m) % m;
} //only for prime m
//Template Completed
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// sort(s.begin(), s.end());
//distance(s.begin(), unique(s.begin(), s.end()))
//s.resize(distance(s.begin(), unique(s.begin(), s.end())))
void check(bool b, string y = "YES", string n = "NO")
{
// b ? cout << "YES\n" : cout << "NO\n";
b ? cout << y << "\n" : cout << n << "\n";
}
bool cmp(pair<ll, ll> a, pair<ll, ll> b)
{
if (a.first < b.first)
return false;
if (a.first > b.first)
return true;
else
return a.second < b.second;
}
void sol6()
{
ll n;
cin >> n;
string s[n];
for (ll x = 0; x < n; x++)
{
cin >> s[x];
}
}
void sol5()
{
ll a, b;
cin >> a >> b;
ll a2 = a, b2 = b;
string s;
cin >> s;
}
void sol4()
{
ll n;
cin >> n;
ll a[n];
for (ll i = 0; i < n; i++)
{
cin >> a[i];
}
}
void sol3()
{
ll n, k;
cin >> n >> k;
}
const ll N = 2 * 1e5 + 10;
ll dp[10][N];
void solve()
{
//Initial Single Digit for Each
for (ll i = 0; i <= 9; i++)
{
dp[i][0] = 1;
}
for (ll j = 1; j < N; j++)
{
//All digits increase only but digits are same
for (ll i = 0; i <= 8; i++)
{
dp[i][j] = dp[i + 1][j - 1];
}
//9 break in 0 and 1
dp[9][j] = mod_add(dp[0][j - 1], dp[1][j - 1], Mod);
}
}
void sol2()
{
ll n, m;
cin >> n >> m;
vector<ll> v(10, 0);
while (n != 0)
{
ll rem = n % 10;
v[rem]++;
n /= 10;
}
ll ans = 0;
for (ll i = 0; i < 10; i++)
{
ll x = dp[i][m];
ll y = v[i];
ans = mod_add(mod_mul(x, y, Mod), ans, Mod);
}
p1(ans);
}
void sol()
{
ll n, l, r, s;
cin >> n >> l >> r >> s;
}
int main()
{
fast;
solve();
test()
{
sol2();
}
}
|
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mk make_pair
#define pb push_back
const int inf=0x3f3f3f3f;
const int maxn=2e5+10;
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
void useiostream()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
ll num[15]={0};
ll nex[15]={0};
ll dp[15][maxn]={0};
void init1()
{
ll ans=0;
for(int i=0;i<=9;i++)
{
dp[i][0]=1;
}
for(int k=0;k<=9;k++)
{
for(int h=0;h<=9;h++)
{
if(h==k)num[h]=1;
else num[h]=0;
}
ans=1;
for(int j=1;j<maxn;j++)
{
for(int i=0;i<=9;i++)
{
if(i==1)
{
nex[i]=(num[0]+num[9])%mod;
}
else if(i==0)nex[0]=num[9];
else nex[i]=num[i-1];
}
ans=(ans+num[9])%mod;
for(int i=0;i<=9;i++)
{
num[i]=nex[i];
}
dp[k][j]=ans;
}
}
}
int main()
{
useiostream();
int T;
cin>>T;
init1();
while(T--)
{
string str;
cin>>str;
ll ans1=0;
int m;
cin>>m;
for(int i=0;i<str.size();i++)
{
ans1=(ans1+dp[str[i]-'0'][m])%mod;
}
cout<<ans1<<endl;
}
}
|
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define fr(i,n) for(int i=0;i<n;i++)
#define fr1(i,k,n) for(int i=k;i<n;i++)
#define foreach(i,arr) for(auto i: arr)
#define sort_inc(a) sort(a.begin(),a.end())
#define sort_dec(a) sort(a.begin(),a.end(),greater<>())
#define exists(a,val) find(a.begin(),a.end(),val)!=a.end()
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T mod(T a){ a %= MOD; if (a<0) a += MOD; return a; }
template <typename T> T add(T a, T b){ return mod(a+b); }
template <typename T> T mul(T a, T b){ return (a * 1ll * b) % MOD; }
template <typename T> T binPow(T a, T b){ T res = 1; while (b>0){ if (b&1) res = mul<T>(res, a); a = mul<T>(a,a); b >>= 1; } return res; }
const int N = 2*1e5 + 5;
int dp[10][N];
void solve(){
int n,m;
cin>>n>>m;
vector<int> a(10);
int n1=n;
while(n1){
a[n1%10]++;
n1 /= 10;
}
int res = 0;
for (int i=0;i<10;i++){
res = add(res, mul(dp[i][m], a[i]));
}
cout<<res<<"\n";
}
int main(int argc, const char * argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
for (int i=0;i<10;i++) dp[i][0] = 1;
for (int i=1;i<N;i++){
for (int j=0;j<=8;j++){
dp[j][i] = dp[j+1][i-1];
}
dp[9][i] = add(dp[0][i-1],dp[1][i-1]);
}
int t=1;
cin>>t;
for (int i=0;i<t;i++){
solve();
}
return 0;
}
|
#include <cmath>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <fstream>
#include <cassert>
using namespace std;
istream& inp = cin;
//ifstream inp("in");
template<typename T>
vector<T> readV(int size) {
vector<T> result;
for (int i = 0; i < size; ++i) { T x; inp >> x; result.push_back(x); }
return result;
}
template<typename T>
T divup(T a, T b) { if ((a % b) == 0) return a / b; return 1 + a / b; }
int64_t constexpr M = 1000000007;
static_assert( M <= (1 << 30));
class modint {
int v;
public:
modint(int x) : v(x % M) {}
modint() : v(0) {}
inline int get() const { return v; }
modint operator + (modint b) { return modint(v + b.v); }
};
vector<modint> len9(200010);
string ns[200010];
int ms[200010];
int32_t main() {
int ntests;
assert(inp);
inp >> ntests;
len9[0] = modint(1);
for (int i = 1; i <= 9; ++i) len9[i] = modint(2);
len9[10] = modint(3);
for (int i = 11; i < 200010; ++i) len9[i] = (len9.at(i - 9) + len9.at(i - 10));
for (int test = 0; test < ntests; ++test ) {
string n;
int n0, m;
inp >> ns[test] >> ms[test];
}
for (int test = 0; test < ntests; ++test ) {
string& n = ns[test];
int m = ms[test];
int64_t result = 0;
assert(n.size() <= 11);
for (int i = 0; i < n.size(); ++i) {
char c = n[i];
assert(c >= '0' && c <= '9');
int m1 = m - (int('9') - int(c));
if (m1 <= 0) result = result + (1); else {
result = result + len9[m1].get();
}
}
cout << (result % M) << "\n";
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 233333;
const ll mod = 1e9 + 7;
ll dp[10][N];
int main() {
int m = 200011;
for(int i = 0; i <= 9; ++i) dp[i][0] = 1;
for(int i = 1; i <= m; ++i) {
for(int d = 0; d <= 9; ++d) {
if(d <= 8) {
dp[d][i] = dp[d+1][i-1];
} else {
dp[d][i] = (dp[1][i-1] + dp[0][i-1]) % mod;
}
}
}
int T, n, k;
cin >> T;
while(T--) {
scanf("%d %d", &n, &k);
int x = n;
ll ans = 0;
while(x) {
int bit = x % 10;
x /= 10;
ans = (ans + dp[bit][k]) % mod;
}
printf("%lld\n", (ans+mod) % mod);
}
}
|
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdlib>
#include <iomanip>
#include<climits>
#include<fstream>
using namespace std;
//=========================MACROS====================================
#define GSK ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ll long long
#define fo(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626
#define mod 1000000007;
#define print2(a,b) cout<<#a<<"="<<(a)<<" "<<#b<<"="<<(b)<<endl;
#define print3(a,b,c) cout<<#a<<"="<<(a)<<" "<<#b<<"="<<(b)<<" "<<#c<<"="<<(c)<<endl;
#define endl "\n"
#define runtime() ((double)clock() / CLOCKS_PER_SEC)
//========================TypeDefs===================================
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef vector<ii> vii;
//======================== JFF ==================================
//void* memset( void* str, int ch, size_t n);
// bool isprime(int n){
// for(int i=2;i<=sqrt(n);i++){
// if(n%i==0) return false;
// }
// return true;
// }
// const int N=1e6+1;
// bool prime[N];
// void SieveOfEratosthenes(int n)
// {
// // Create a boolean array
// // "prime[0..n]" and initialize
// // all entries it as true.
// // A value in prime[i] will
// // finally be false if i is
// // Not a prime, else true.
// memset(prime, true, sizeof(prime));
// for (int p = 2; p * p <= n; p++)
// {
// // If prime[p] is not changed,
// // then it is a prime
// if (prime[p] == true)
// {
// // Update all multiples
// // of p greater than or
// // equal to the square of it
// // numbers which are multiple
// // of p and are less than p^2
// // are already been marked.
// for (int i = p * p; i <= n; i += p)
// prime[i] = false;
// }
// }
// // Print all prime numbers
// // for (int p = 2; p <= n; p++)
// // if (prime[p])
// // cout << p << " ";
// }
// inline ll power(ll x, ll y, ll p = mod)
// {
// ll res = 1;
// x = x % p;
// while (y > 0)
// {
// if (y & 1)
// res = (res * x) % p;
// y = y >> 1;
// x = (x * x) % p;
// }
// return res;
// }
// inline ll modadd(ll a, ll b, ll m = mod)
// {
// a += b;
// if (a >= m)
// a -= m;
// return a;
// }
// inline ll modmul(ll a, ll b, ll m = mod)
// {
// return ((a % m) * (b % m)) % m;
// }
// inline ll modi(ll a, ll m = mod) { return power(a, m - 2, m); }
// long long int inverse(long long int i,ll m=mod){
// if(i==1) return 1;
// return (m - ((m/i)*inverse(m%i))%m+m)%m;
// }
void hehe(bool ok){
cout<<(ok?"YES":"NO")<<endl;
}
int foo(int a,int b){
return b*((a+b-1)/b)-a;
}
//======================== JFF ==================================
const int M=200015;
int pre[M];
void q1(){
int n,m;
cin>>n>>m;
vi a;
while(n>0){
a.pb(n%10);
n/=10;
}
int ans=0;
for(int x: a){
ans=(ans+pre[x+m])%mod;
}
cout<<ans<<endl;
}
/*
1
2 1 1 3
*/
int32_t main()
{
GSK;
// fo(i,N) fac[i]=1;
// for(int i=1;i<N;i++){
// fac[i]=(fac[i-1]*i)%mod;
// }
fo(i,10) pre[i]=1;
for(int i=10;i<M;i++){
pre[i]=(pre[i-10]+pre[i-9])%mod;
}
int cases=1;
cin >> cases;
for(int t_case=1;t_case<=cases;t_case++)
{
// cout<<"Case #"<<t_case<<": ";
q1();
}
//cerr<<runtime();
return 0;
}
|
#include <bits/stdc++.h>
#define PI 3.14159265359
#define lp(i, n) for (size_t i = 0; i < n; i++)
typedef long long ll;
typedef long double ld;
using namespace std;
const char nl = '\n';
const ll MOD = (ll)1e9 + 7;
vector<ll> lenDigit(int d, int m) {
ll occ[10] = {0};
occ[d] = 1;
vector<ll> v;
v.push_back(1);
while (m--) {
ll nine = occ[9];
for (int i = 9; i > 0; i--) {
occ[i] = occ[i - 1];
}
occ[0] = nine;
occ[1] += nine;
occ[1] %= MOD;
v.push_back((v.back() + nine) % MOD);
}
return v;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
vector<ll> res[10];
for (int i = 0; i < 10; i++) {
res[i] = lenDigit(i, 2 * (int)1e5);
}
while (t--) {
ll n;
int m;
cin >> n >> m;
ll ret = 0;
while (n) {
ret += res[n % 10][m];
ret %= MOD;
n /= 10;
}
cout << ret << nl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,n) for(ll i=a ;i<n ;i++)
#define fr(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define read(a,n) for(ll i=0 ;i<n ;i++)cin>>a[i]
#define F first
#define S second
#define endl "\n"
bool pali(string s)
{
for(ll i=0 ;i<s.size()/2 ;i++)
if(s[i]!=s[s.size()-i-1])
return false;
return true;
}
void no(){
cout<<-1<<endl;
}
void yes(){
cout<<"YES\n";
}
ll mod=1000000007;
///////////////////////////////////////////////////////////////////
ll dp[10][200005]={0};
ll solve(int n ,int m)
{
if(m<10-n)
return 1;
if(dp[n][m]!=0)
return dp[n][m]%mod;
else{
dp[n][m]=((solve(1,m-(10-n))%mod)+(solve(0,m-(10-n)))%mod)%mod;
return dp[n][m];
}
}
int size(int n)
{
int ans=0;
while(n>0)
{
ans++;
n/=10;
}
return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll t = 1;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
ll ans=0;
while(n>0)
{
ans+=(solve(n%10,m)%mod);
ans%=mod;
n/=10;
}
cout<<ans<<endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int max_n = 200005, mod = 1000000007;
int p[max_n];
signed main() {
for (int i = 0; i < 9; i ++)p[i] = 2;
p[9] = 3;
for (int i = 10; i < max_n; i ++) {
p[i] = (p[i - 9] + p[i - 10]) % mod;
}
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t --) {
int n, m;
cin >> n >> m;
int ans = 0;
while (n > 0) {
int x = n % 10;
ans += ((m + x < 10) ? 1 : p[m + x - 10]);
ans %= mod;
n /= 10;
}
cout << ans << "\n";
}
return 0;
}
|
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
long long t,n,sum[10],total[200001],temp,temp1,temp2,inf=1000000007,j,ans,formulation;
long long i,m,xiao=200000;
for(i=0; i<10; i++)
sum[i]=0;
sum[0]=1;
sum[1]=1;
total[0]=2;
for(i=1; i<=xiao; i++)
{
temp=sum[8]%inf;
sum[8]=sum[7]%inf;
sum[7]=sum[6]%inf;
sum[6]=sum[5]%inf;
sum[5]=sum[4]%inf;
sum[4]=sum[3]%inf;
sum[3]=sum[2]%inf;
sum[2]=sum[1]%inf;
sum[1]=sum[0]%inf+sum[9]%inf;
sum[0]=sum[9]%inf;
sum[9]=temp;
total[i]=(sum[0]+sum[1]+sum[2]+sum[3]+sum[4]+sum[5]+sum[6]+sum[7]+sum[8]+sum[9])%inf;
}
scanf("%lld",&t);
for(j=0; j<t; j++)
{
ans=0;
scanf("%lld%lld",&n,&m);
while(n!=0)
{
formulation=m+n%10-10;
if(formulation<0)
ans=(ans+1)%inf;
else
{
ans=(ans+total[formulation])%inf;
}
n=n/10;
}
printf("%d\n",ans%inf);
}
return 0;
}
|
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <limits>
#include <numeric>
using namespace std;
const int MOD = 1e9 + 7;
struct matrix {
int size = 10;
int a[10][10];
matrix() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
a[i][j] = 0;
}
}
}
matrix operator *(matrix& other) {
matrix product;
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
for (int k = 0; k < size; k++) {
product.a[i][k] += a[i][j] * other.a[j][k] % MOD;
product.a[i][k] %= MOD;
}
}
}
return product;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
vector<matrix> m(200001);
matrix trans;
trans.a[0][9] = 1;
trans.a[1][9] = 1;
for (int i = 1; i <= 9; i++) {
trans.a[i][i - 1] = 1;
}
for (int i = 0; i <= 9; i++) {
m[0].a[i][i] = 1;
}
for (int i = 1; i <= 200000; i++) {
m[i] = trans * m[i - 1];
}
int tt;
cin >> tt;
while (tt--) {
string s;
int k;
cin >> s >> k;
int cnt[10];
for (int i = 0; i < 10; i++) {
cnt[i] = 0;
}
for (char c : s) {
cnt[c - '0']++;
}
long long answer = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
answer = (answer + (long long)m[k].a[i][j] * cnt[j]) % MOD;
}
}
cout << answer << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int m=200000;
int p=1000000007;
vector<int> dp(m+1);
for(int i=0;i<9;i++){dp[i]=2;}
dp[9]=3;
for(int i=10;i<=m;i++){dp[i]=(dp[i-10]+dp[i-9])%p;}
int t;
cin>>t;
while(t--){
int n,x;
cin>>n>>x;
int ans=0;
while(n!=0){
int d=n%10;
n/=10;
if(d+x<10){ans=(ans+1)%p;}
else{ans=(ans+dp[d+x-10])%p;}
}
cout<<ans<<endl;
}
return 0;
}
|
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<functional>
#include<iterator>
int main()
{
vector<int> operate;
for (int i = 0; i < 200001; i++)
{
if (i < 9)
operate.push_back(2);
if (i == 9)
operate.push_back(3);
if (i > 9)
operate.push_back((operate[i - 9] + operate[i - 10]) % 1000000007);
}
int t;
cin >> t;
vector<int> answer;
for (int i = 0; i < t; i++)
{
int n, m;
cin >> n >> m;
answer.push_back(0);
while (n)
{
if (m - 10 + n % 10 >= 0)
{
answer[i] += operate[m - 10 + n % 10];
}
else
answer[i] += 1;
answer[i] %= 1000000007;
n /= 10;
}
}
copy(answer.begin(), answer.end(), ostream_iterator<int>(cout, "\n"));
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int X=0; bool flag=1; char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
if(flag) return X;
return ~(X-1);
}
int T,n,m;
typedef long long ll;
ll mod=1e9+7,ans=0ll;
ll f[200050];
int main(){
cin>>T;
for(int i=0;i<=8;i++){
f[i]=2ll;
}
for(int i=9;i<=200005;i++){
if(i<10)f[i]=f[i-9]+1;
else f[i]=f[i-9]+f[i-10];
if(f[i]>mod)f[i]%=mod;
}
while(T--){
n=read();m=read();
ans=0ll;
while(n){
int t=n%10;
if(m>=10-t)ans+=f[m-(10-t)];
else ans++;
n/=10;
if(ans>mod)ans%=mod;
}
printf("%d\n",ans%mod);
}
}
|
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm> // for copy
#include <iterator> // for ostream_iterator
using namespace std;
const int P = 1000000007;
const int M = 200000;
int answer_for_0[M+10];
// the result for the digit 0 is answer_for_0[m]
// the result for any other digit d is answer_for_0[m+d]
int main (){
for (int i=0;i<10;i++)
answer_for_0[i] = 1;
for (int i=10; i<M+10; i++)
answer_for_0[i] = (answer_for_0[i-10] + answer_for_0[i-9])%P;
int t;
cin >> t;
vector<int> answers (t);
for (int i=0; i<t; i++){
int n, m;
cin >>n >>m;
int ans = 0;
while(n > 0){
ans = (ans+ answer_for_0[m+ n%10] )%P ;
n/=10;
}
answers[i] = ans;
}
copy ( answers.begin(), answers.end(), ostream_iterator<int>(cout, "\n") );
return 0;
}
|
// Просто решаю.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//
//KiruxaLight
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <iomanip>
#include <stack>
#include <deque>
#include <queue>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cassert>
#include <bitset>
using namespace std;
#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const int INF = 1e9 + 123, MAXN = 2e5, MEGAINF = 1e18, C = 50;
const int mod = 1e9 + 7;
int dp[10][MAXN + 1];
void init()
{
for (int i = 0; i < 10; ++i)
dp[i][0] = 1;
for (int i = 1; i <= MAXN; ++i)
{
for (int j = 0; j < 9; ++j)
dp[j][i] = dp[j + 1][i - 1];
dp[9][i] = (dp[1][i - 1] + dp[0][i - 1]) % mod;
}
}
signed main()
{
setlocale(LC_ALL, "rus");
/*freopen(".in", "r", stdin);
freopen(".out", "w", stdout);*/
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
init();
/*for (int i = 0; i <= MAXN; ++i, cout << endl)
for (int j = 0; j < 10; ++j)
cout << dp[j][i] << " ";*/
int t;
cin >> t;
while (t--)
{
int n, m;
cin >> n >> m;
int ans = 0;
while (n)
{
ans = (ans + dp[n % 10][m]) % mod;
n /= 10;
}
cout << ans << "\n";
}
}
// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
// Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
// Советы по началу работы
// 1. В окне обозревателя решений можно добавлять файлы и управлять ими.
// 2. В окне Team Explorer можно подключиться к системе управления версиями.
// 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
// 4. В окне "Список ошибок" можно просматривать ошибки.
// 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
// 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.
|
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define gap ' '
#define fastIO {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define Inf 1e18
#define MOD 1000000007
#define N 1000006
#define all(v) v.begin(),v.end()
#define For(i, a, b) for(ll i = a; i < b; ++i)
#define Rof(i, a, b) for(ll i = a; i >= b; --i)
#define endl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef multimap<ll, ll> mmll;
ll dp[200500];
void start() {
For(i, 0, 10) dp[i] = 1;
For(i, 10, 200500)
dp[i] = (dp[i - 10] + dp[i - 9]) % MOD;
}
void solve()
{
ll t; t = 1; cin>>t; t:
start();
while(t --)
{
ll n, m; cin>>n>>m;
ll ans = 0;
while(n)
{
ll k = n%10;
ans = (ans + dp[k + m])%MOD;
n/=10;
}
cout<< ans <<endl;
}
}
int main()
{
fastIO
solve();
return 0;
}
|
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mxn=2e5+10,mod=1e9+7;
int dp[12][mxn];
int main()
{
int arr[]={1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2};
for(int i=0;i<=9;i++)
for(int j=0;j<10;j++)
dp[i][j]=arr[i+j];
for(int i=0;i<=9;i++)
for(int j=10;j<mxn;j++)
dp[i][j]=(dp[i][j-10]%mod+dp[i][j-9]%mod)%mod;
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
int res=0;
while(n!=0)
{
int rem=n%10;
res=(res%mod+dp[rem][m]%mod)%mod;
n/=10;
}
printf("%d\n",res);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int big = pow(10, 9) + 7, size = 200000;
int tt;
cin >> tt;
vector<ll> dp(size+1);
dp[0] = 1;
for (int i = 0; i < size; i++)
{
if (i + 9 < size)
dp[i + 9] = (dp[i + 9] + dp[i]) % big;
if (i + 10 < size)
dp[i + 10] = (dp[i + 10] + dp[i]) % big;
}
for (int i = 1; i < size; i++)
{
dp[i] = (dp[i] + dp[i - 1]) % big;
}
while (tt--)
{
string s;
ll m, ans = 0;
cin >> s >> m;
ans = s.size();
vector<ll> num(10);
for (int i = 0; i < s.size(); i++)
{
int n = s[i] - '0';
num[n]++;
}
for (int i = 0; i < 10; i++)
{
if (m < (10 - i))
continue;
ans = (ans + num[i] * dp[m - (10 - i)]) % big;
}
cout << ans << "\n";
}
return 0;
}
|
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<stack>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int mod = 1e9 + 7;
ll t, n, m;
int dp[200500];
int main(){
fast;
for (int i = 0; i < 9;i++){
dp[i] = 2;
}
dp[9] = 3;
for (int i = 10; i < 200005;i++){
dp[i] = (dp[i - 9] + dp[i - 10]) % mod;
}
cin >> t;
while(t--){
cin >> n >> m;
ll ans = 0;
while(n>0){
int x = n % 10;
ans += ((m + x < 10) ? 1 : dp[m + x - 10]);
ans %= mod;
n /= 10;
}
cout << ans << "\n";
}
return 0;
}
|
#include<bits/stdc++.h>
#define MAX 200000
#define MOD 1000000007
using namespace std;
int dp[11][MAX+10];
int go(int x,int m)
{
if(dp[x][m]!=-1)
return dp[x][m];
if(m==0)
return dp[x][m] = 1;
if(x==9)
return dp[x][m] = (go(1,m-1)+go(0,m-1))%MOD;
return dp[x][m] = go(x+1,m-1);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
for(int i=0;i<=9;++i)
for(int j=0;j<=MAX;++j)
dp[i][j] = -1;
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
int m;
cin>>m;
long long ans = 0;
for(char c:s)
ans += go(c-'0',m)*1LL, ans %= MOD;
cout<<ans<<endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <bitset>
#include <math.h>
#include <fstream>
#include <iomanip>
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vld = vector<ld>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using pb = pair<bool, bool>;
using vpb = vector<pb>;
using vvpb = vector<vpb>;
using vi = vector<int>;
const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e18;
#define F first
#define S second
#define FAST ios_base::sync_with_stdio(0)
#define FASTIN cin.tie(0)
#define FASTOUT cout.tie(0)
#define upmin(a, b) a = min(a, b)
#define upmax(a, b) a = max(a, b)
#define whatvec(v) cout << #v << ": "; for(auto it = v.begin(); it != v.end(); ++it) cout << *it << " "; cout << endl;
#define prv(v) cout << #v << ": "; for(auto it = v.begin(); it != v.end(); ++it) cout << *it << " "; cout << endl;
#define wpr(x) cout << #x << " = " << (x) << endl;
#define wprv(v) cout << #v << ": "; for(auto it = v.begin(); it != v.end(); ++it) cout << *it << " "; cout << endl;
#define what(x) cout << #x << " = " << (x) << "\n";
#define pr(x) cout <<x << endl;
#define rep(i,s,e) for(int i=s;i<e;i++)
#define all(x) x.begin(),x.end()
#define pb push_back
// 13:52
const ll maxn = 2e5 + 5;
vvll dp; // [len][dig]
void init_dp()
{
dp.resize(maxn, vll(10, 1));
for (ll i = 1; i < maxn; i++) {
for (ll dig = 0; dig < 9; dig++) {
dp[i][dig] = (dp[i - 1][dig + 1])%mod;
}
dp[i][9] = (dp[i - 1][1] + dp[i - 1][0])%mod;
}
}
void solve()
{
ll n, m;
cin >> n >> m;
ll ans = 0;
while (n) {
ll d = n % 10;
ans += dp[m][d];
ans %= mod;
n /= 10;
}
pr(ans);
}
int main()
{
init_dp();
FAST;
ll test;
cin >> test;
while (test--)
{
solve();
}
}
|
#include<bits/stdc++.h>
using namespace std;
long long m=200000,k=1;
long long sum[200001][10]={{}};
long long a[10]={1,1,1,1,1,1,1,1,1,1},b[10];
int main(){
ios_base::sync_with_stdio(false);
long long j=9;
k=1;
ios_base::sync_with_stdio(false);
for(long long i=0;i<=9;i++)
a[i]=0;
a[j]=1;
while(k<=m)
{
for(long long i=0;i<=9;i++)
b[i]=0;
for(long long i=0;i<=9;i++){
if(i<=8)
{
b[i+1]+=a[i];
b[i+1]%=1000000007;}
else if(i==9)
{
b[1]+=a[i];b[0]+=a[i];
b[1]%=1000000007;b[1]%=1000000007;}
a[i]=0;
}
ios_base::sync_with_stdio(false);
//if(k==1&&j==9)
//cout<<b[9]<<endl;
for(long long i=0;i<=9;i++)
a[i]=b[i];
for(long long i=0;i<=9;i++)
{
sum[k][j]+=a[i];
sum[k][j]%=1000000007;
}
k++;}
ios_base::sync_with_stdio(false);
long long t;
cin>>t;
while(t--){
ios_base::sync_with_stdio(false);
long long n,m;
cin>>n>>m;
long long p=0;
while(n!=0){
long long x;
x=n%10;
if(x==9)
p+=sum[m][x];
else if(m>(9-x))
p+=sum[m-9+x][9];
else
p+=1;
p%=1000000007;
n=n/10;
}
cout<<p<<endl;
}
//cout<<"5\n2\n6\n4\n2115";
}
|
#include<bits/stdc++.h>
#define mp make_pair
#define s second
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(),v.end()
#define mx(a,b) a>b?a:b
#define mn(a,b) a<b?a:b
using namespace std;
const int maxn = 5+2e5;
typedef long long ll;
const int mod = 1e9+7;
int dp[maxn];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for(int i = 0;i < 9;i++)dp[i] = 2;
dp[9] = 3;
for(int i = 10;i < maxn;i++){
dp[i] = (dp[i-9] + dp[i-10]) % mod;
}
while(t--){
ll sol = 0;
string k;
int m;
cin >> k >> m;
for(auto i: k){
if(m + (int)(i-'0') < 10)sol++;
else sol += dp[m-10+(int)(i-'0')];
sol %= mod;
}
cout << sol << "\n";
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i = k ;i<=n;i++)
#define FO(i,n,k) for(int i = n;i>=k;i--)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define mems(a,x) memset(a,x,sizeof(a))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<pair<int, int> , int > piii;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
uniform_int_distribution<int> uid(0, lim - 1);
return uid(rang);
}
const int mod = 1000000007 ;//998244353; //;
//const int N = 3e5, M = N;
vector<ll> dp;
void solve()
{
ll n, m;
cin >> n >> m;
ll ans = 0;
while (n > 0)
{
ll t = n % 10;
if (t + m >= 10)
{
ans = (ans + dp[m - (10 - t)]) % mod;
}
else
{
ans = (ans + 1) % mod;
}
// ans = (ans + f(n % 10, m)) % mod;
n /= 10;
}
cout << ans << endl;
// dp.clear();
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
int t = 1;
cin >> t;
dp.resize(200002, -1);
fo(i, 10)
dp[i] = 2;
dp[9] = 3;
Fo(i, 10, 200002)
{
dp[i] = (dp[i - 10] + dp[i - 9]) % mod;
}
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define fab(i,a,b) for(i=a;i<=b;i++)
#define fabr(i,a,b) for(i=b;i>=a;i--)
#define f(i,n) for(i=0;i<n;i++)
#define sc second
#define fr first
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define max 1000000000000000000
#define nl "\n"
using namespace std;
ll dp[200001];
void fun()
{
ll i;
f(i,200001)
{
if(i<=8)
dp[i]=2;
else if(i==9)
dp[i]=3;
else
dp[i]=(dp[i-9]+dp[i-10])%mod;
}
}
int main()
{
FAST;
ll t,i,m,z,u,ans,b,c,l,q,p,j,sum,d,n,a,x,y,k,w,h,r;
t=1;
char ch;
string s,aa,bb,dd,rr,tt,ss="";
fun();
cin>>t;
while(t--)
{
ans=0;
cin>>n>>m;
//cout<<dp[92]<<nl;
while(n>0)
{
k=n%10;
if(k+m<10)
ans+=1;
else
ans+=dp[k+m-10];
ans%=mod;
n=n/10;
}
cout<<ans<<nl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int mod = 1e9 + 7;
int dp[MAXN][10];
void solve()
{
for(int i = 0; i <= 9; i++)
{
dp[0][i] = 1;
}
for(int i = 1; i < MAXN; i++)
{
for(int j = 0; j <= 9; j++)
{
if(j == 9)
dp[i][j] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
else
dp[i][j] = dp[i - 1][j + 1];
}
}
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
solve();
int t, m, num;
cin >> t;
while(t--)
{
num = 0;
string str;
cin >> str >> m;
int z = str.size();
for(int i = 0; i < z; i++)
{
num += dp[m][str[i] - '0'] ;
num = num % mod;
}
cout << num << endl;
}
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define debug(x) cout << #x << " is " << x << endl
typedef pair<int, int> pii;
typedef long long ll;
const int INF = 0x3f3f3f3f, N = 2e5 + 15;
const ll MOD = 1e9 + 7;
int t, n, m;
ll a[N];
int main()
{
for (int i = 0; i <= 9; ++i) a[i] = 1;
for (int i = 10; i <= N; ++i) a[i] = (a[i-9] + a[i-10]) % MOD;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
ll ans = 0;
while (n) {
(ans += a[n%10+m]) %= MOD;
n /= 10;
}
printf("%lld\n", ans);
}
return 0;
}
|
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
#define rep(i,j,n) for(int i=(j);i<=((int)n);++i)
#define rev(i,n,j) for(int i=(n);i>=((int)j);--i)
typedef long long int ll;
#define int long long int
const ll INFL=0x3f3f3f3f3f3f3f3fLL;
const int INF=0x3f3f3f3f;
const int mod=1000000007;
#define endl "\n"
#define mem(a,val) memset(a,val,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define pb push_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define readmat(a, n, m) int a[n + 5][m + 5] = {}; rep(i, 1, n) {rep(j, 1, m) cin >> a[i][j];}
#define printmat(a, n, m) rep (i, 1, n) {rep (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define printarr(a, n) rep(i, 1, n) cout << a[i] << " "; cout << endl;
typedef std::map< int,int> mii;
typedef std::vector< int > vi;
typedef std::vector< vi > vvi;
typedef std::pair< int,int > ii;
using namespace std;
#define cerr cout
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " = " << a << endl;
err(++it, args...);}
const int N = 2e5+5, M = 2e5;
vector <int>g[N];
int dp[15][N];
void pre()
{
for(int i = 0; i <10; ++i)
{
int cnt[11]={0};
int ncnt[11]={0};
cnt[i]=1;
for(int j = 1; j <=M; ++j)
{
for(int k = 0; k <10; ++k)
{
ncnt[k]=0;
}
for(int k = 0; k <10; ++k)
{
if (k!=9)
{
ncnt[k+1]=(cnt[k]%mod);
}
else
{
ncnt[0]=(ncnt[0]+cnt[k])%mod;
ncnt[1]=(ncnt[1]+cnt[k])%mod;
}
}
int s=0;
for(int k = 0; k <10; ++k)
{
cnt[k]=(ncnt[k]%mod);
s=(s+cnt[k])%mod;
}
dp[i][j]=s;
}
}
}
void solve()
{
string n;
int m;
cin>>n>>m;
mii x;
for(auto &i : n)
{
x[i-'0']++;
}
int ans=0;
for(auto &[i,j] : x)
{
ans=(ans+(dp[i][m]*j)%mod)%mod;
}
cout<<ans<<endl;
}
signed main()
{
FAST;
#ifdef LOCAL
freopen("C:\\Users\\hp\\Documents\\input.txt", "r", stdin);
freopen("C:\\Users\\hp\\Documents\\output.txt", "w", stdout);
std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
start = std::chrono::high_resolution_clock::now();
#endif
pre();
int t;
cin>>t;
while(t--)
{
solve();
}
#ifdef LOCAL
end = std::chrono::high_resolution_clock::now();
ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
cout<<endl;
cout << "\nElapsed Time: " << elapsed_time << "ms\n";
#endif
return 0;
}
// vector string set map first second continue break return upper_bound lower_bound length void sort
// stack queue pop size erase empty insert
// #Hala BBCF
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 1000000007
#define vi vector<int>
#define vl vector<long long>
#define pi pair<int,int>
#define pl pair<long long,long long>
#define pb push_back
#define mi map<int,int>
#define ml map<long long,long long>
ll dp[10][200001];
ll a[10];
ll b[10];
void makedp()
{
ll i,j,ii,sz=0;
for(i=0;i<10;i++)
{
dp[i][0]=1;
}
for(i=0;i<10;i++)
{
sz=1;
for(j=0;j<10;j++){a[j]=0;b[j]=0;}
a[i]=1;
for(j=1;j<=200000;j++)
{
for(ii=0;ii<10;ii++)
{
if(ii==9)
{
sz+=a[ii];b[0]+=a[ii];b[1]+=a[ii];a[ii]=0;
}
else
{
b[ii+1]+=a[ii];a[ii]=0;
}
}
dp[i][j]=sz;
for(ii=0;ii<10;ii++)
{
a[ii]=b[ii];
a[ii]=a[ii]%MAX;
b[ii]=0;
}
}
}
// for(i=0;i<=20;i++)
// {
// cout<<dp[1][i]<<" ";
// }
// printf("\n");
}
int main()
{
makedp();
int t;scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d %d",&n,&m);
ll s=0;
while(n)
{
//cout<<dp[n%10][m]<<" ";
s+=dp[n%10][m];
s=s%MAX;
n/=10;
}
printf("%lld\n",s%MAX);
}
return 0;
}
|
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
template<typename T, typename U>
pair<T, U> operator+(const std::pair<T, U> &l, const std::pair<T, U> &r) {
return {l.first + r.first, l.second + r.second};
}
template<typename T, typename U>
pair<T, U> operator-(const std::pair<T, U> &l, const std::pair<T, U> &r) {
return {l.first - r.first, l.second - r.second};
}
const int N =2e5 + 10;
int dp[N][10];
int solve(int num , int m){
if(dp[m][num]!=-1){
return dp[m][num];
}
if(m==0){
return 1;
}
num++;
ll ans = 0;
if(num==10){
ans+=solve(1,m-1);
ans+=solve(0,m-1);
ans%=MOD;
}else{
ans=solve(num,m-1);
}
return dp[m][num-1] = ans;
}
int main() {
IO;
int t;
cin>>t;
memset(dp,-1,sizeof dp);
while (t--){
string str;
cin>>str;
int m ;
cin>>m ;
ll ans = 0 ;
for(char ch : str){
ans+=solve(ch-'0',m);
ans%=MOD;
}
cout<<ans<<endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int max_n = 200005, mod = 1000000007;
int dp[max_n];
signed main(){
for(int i=0; i<9; i++)dp[i] = 2;
dp[9] = 3;
for(int i=10; i<max_n; i++){
dp[i] = (dp[i-9] + dp[i-10])%mod;
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int n, m;
cin>>n>>m;
int ans = 0;
while(n > 0){
int x = n%10;
ans += ((m + x < 10) ? 1 : dp[m + x - 10]);
ans %= mod;
n/=10;
}
cout<<ans<<"\n";
}
return 0;
}
|
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
template <int M>
struct MInt {
unsigned int val;
MInt(): val(0) {}
MInt(long long x) : val(x >= 0 ? x % M : x % M + M) {}
static constexpr int get_mod() { return M; }
static void set_mod(int divisor) { assert(divisor == M); }
static void init(int x = 10000000) { inv(x, true); fact(x); fact_inv(x); }
static MInt inv(int x, bool init = false) {
// assert(0 <= x && x < M && std::__gcd(x, M) == 1);
static std::vector<MInt> inverse{0, 1};
int prev = inverse.size();
if (init && x >= prev) {
// "x!" and "M" must be disjoint.
inverse.resize(x + 1);
for (int i = prev; i <= x; ++i) inverse[i] = -inverse[M % i] * (M / i);
}
if (x < inverse.size()) return inverse[x];
unsigned int a = x, b = M; int u = 1, v = 0;
while (b) {
unsigned int q = a / b;
std::swap(a -= q * b, b);
std::swap(u -= q * v, v);
}
return u;
}
static MInt fact(int x) {
static std::vector<MInt> f{1};
int prev = f.size();
if (x >= prev) {
f.resize(x + 1);
for (int i = prev; i <= x; ++i) f[i] = f[i - 1] * i;
}
return f[x];
}
static MInt fact_inv(int x) {
static std::vector<MInt> finv{1};
int prev = finv.size();
if (x >= prev) {
finv.resize(x + 1);
finv[x] = inv(fact(x).val);
for (int i = x; i > prev; --i) finv[i - 1] = finv[i] * i;
}
return finv[x];
}
static MInt nCk(int n, int k) {
if (n < 0 || n < k || k < 0) return 0;
if (n - k > k) k = n - k;
return fact(n) * fact_inv(k) * fact_inv(n - k);
}
static MInt nPk(int n, int k) { return n < 0 || n < k || k < 0 ? 0 : fact(n) * fact_inv(n - k); }
static MInt nHk(int n, int k) { return n < 0 || k < 0 ? 0 : (k == 0 ? 1 : nCk(n + k - 1, k)); }
static MInt large_nCk(long long n, int k) {
if (n < 0 || n < k || k < 0) return 0;
inv(k, true);
MInt res = 1;
for (int i = 1; i <= k; ++i) res *= inv(i) * n--;
return res;
}
MInt pow(long long exponent) const {
MInt tmp = *this, res = 1;
while (exponent > 0) {
if (exponent & 1) res *= tmp;
tmp *= tmp;
exponent >>= 1;
}
return res;
}
MInt &operator+=(const MInt &x) { if((val += x.val) >= M) val -= M; return *this; }
MInt &operator-=(const MInt &x) { if((val += M - x.val) >= M) val -= M; return *this; }
MInt &operator*=(const MInt &x) { val = static_cast<unsigned long long>(val) * x.val % M; return *this; }
MInt &operator/=(const MInt &x) { return *this *= inv(x.val); }
bool operator==(const MInt &x) const { return val == x.val; }
bool operator!=(const MInt &x) const { return val != x.val; }
bool operator<(const MInt &x) const { return val < x.val; }
bool operator<=(const MInt &x) const { return val <= x.val; }
bool operator>(const MInt &x) const { return val > x.val; }
bool operator>=(const MInt &x) const { return val >= x.val; }
MInt &operator++() { if (++val == M) val = 0; return *this; }
MInt operator++(int) { MInt res = *this; ++*this; return res; }
MInt &operator--() { val = (val == 0 ? M : val) - 1; return *this; }
MInt operator--(int) { MInt res = *this; --*this; return res; }
MInt operator+() const { return *this; }
MInt operator-() const { return MInt(val ? M - val : 0); }
MInt operator+(const MInt &x) const { return MInt(*this) += x; }
MInt operator-(const MInt &x) const { return MInt(*this) -= x; }
MInt operator*(const MInt &x) const { return MInt(*this) *= x; }
MInt operator/(const MInt &x) const { return MInt(*this) /= x; }
friend std::ostream &operator<<(std::ostream &os, const MInt &x) { return os << x.val; }
friend std::istream &operator>>(std::istream &is, MInt &x) { long long val; is >> val; x = MInt(val); return is; }
};
namespace std { template <int M> MInt<M> abs(const MInt<M> &x) { return x; } }
using ModInt = MInt<MOD>;
constexpr int M = 200000;
ModInt dp[10][M + 1]{};
void solve() {
string n; int m; cin >> n >> m;
ModInt ans = 0;
for (char c : n) ans += dp[c - '0'][m];
cout << ans << '\n';
}
int main() {
REP(i, 10) dp[i][0] = 1;
FOR(j, 1, M + 1) REP(i, 10) {
for (char c : to_string(i + 1)) dp[i][j] += dp[c - '0'][j - 1];
}
int t; cin >> t;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
//define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x <<'\t' << x <<endl
#else
#define debug(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
#define lowbit(x) ((x) & -(x))
#define mem(a, b) memset(a, b, sizeof(a))
#define PI acos(-1)
#define endl '\n'
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
//#define int long long
//ll gcd(ll a, ll b){a = abs(a);b = abs(b);return a == 0 ? b : gcd(b % a, a);}
//inline ll Pow(ll a, ll n, ll MOD) { ll t = 1; a %= MOD; while (n > 0) { if (n & 1) t = t * a % MOD; a = a * a % MOD, n >>= 1; } return t % MOD; }
#define int long long
const int maxn = 2e5+100;
int a[20][maxn];
ll solve(int x,int m)
{
if(a[x][m]!=-1) return a[x][m];
if(x+m<10) return 1;
ll res = 0;
res += solve(1,m-(10-x));
res %= mod;
res += solve(0,m-(10-x));
res %= mod;
return a[x][m] = res;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
fast;
int T;
cin>>T;
mem(a,-1);
while(T--){
int n,m;
cin>>n>>m;
ll res = 0;
while(n){
res += solve(n%10,m);
res = res%mod;
n /= 10;
}
cout<<res<<endl;
}
return 0;
}
|
#include<bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>
#define ull unsigned long long int
//#define lli long long int
#define int long long int
#define NUM 1000000007
#define mp make_pair
#define pb push_back
#define ITR ::iterator
#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
//ull power(ull x, ull n) {
// if (n == 0)
// return 1;
//
// if (n % 2 == 0) {
// ull y = power(x, n / 2);
// return (y * y);
// }
// else return ((x * pow(x, n - 1)));
//}
int fact(int n)
{
int ans = 1;
while (n)
{
ans = (ans * n) % NUM;
n--;
}
return ans;
}
const int maxn = 2e5 + 1;
int dp[10][maxn];
int rec(int n, int m)
{
if (m <= 0 or m < (10 - n)) return 1;
if (dp[n][m] != -1) return dp[n][m];
if (n + m >= 10) return dp[n][m] = (rec(1, m - 10 + n) + rec(0, m - 10 + n)) % NUM;
return dp[n][m];
}
signed main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
fast_io
int t;
cin >> t;
vector<int> v;
memset(dp, -1, sizeof dp);
while (t--) {
v.clear();
int i, n, m, ans = 0;
cin >> n >> m;
while (n)
{
ans += rec(n % 10, m);
n /= 10;
ans %= NUM;
}
cout << ans << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MAXM 200015
long long y;
int pd[MAXM];
int solve(int x){
if(x < 0) return 0;
if(pd[x] == -1){
if(x <= 9) pd[x] = 1;
else{
y = (solve(x - 10) + solve(x - 9));
if(y > MOD) y -= MOD;
pd[x] = y;
}
}
return pd[x];
}
int main(){
int t; scanf("%d", &t);
memset(pd, -1, sizeof pd);
solve(MAXM - 1);
while(t--){
char n[10]; scanf("%s", n);
int m; scanf("%d", &m);
long long ans = 0;
for(int i = 0; n[i]; ++i){
int z = n[i] - '0';
ans += solve(m + z);
ans %= MOD;
}
printf("%lld\n", ans);
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
//typedef unsigned long long int ull;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<vector<ll>> v(10,vector<ll> (200001,0));
ll A[10];ll B[10] = {0};
ll maxx = 200000;
for(int I=0;I<10;++I){
for(int j=0;j<10;++j){
if(j==I)A[j] = 1;
else A[j]=0;
}
for(ll k=0;k<maxx;++k){
for(int i=0;i<10;++i){
if(i==0)B[0] = (A[9])%mod;
else if(i==1)B[1] = (A[0] + A[9])%mod;
else B[i] = (A[i-1])%mod;
}
ll count =0;
for(int i=0;i<10;++i){A[i] = B[i];count = (count + A[i])%mod;}
v[I][k+1] = count;
}
}
int t=1;cin>>t;
while(t--){
string s;ll m;
cin>>s>>m;
ll ans = 0;
for(int i=0;i<(int)s.length();++i){
ans = (ans + v[s[i]-'0'][m])%mod;
}
//cout<<"here ";
cout<<ans<<endl;
/*
ll a[10] = {0}, b[10] = {0};
for(int i=0;i<(int)s.length();++i){
a[s[i]-'0']++;
}
//for(int i=0;i<10;++i)cout<<a[i]<<" ";
while(m--){
for(int i=0;i<10;++i){
if(i==0)b[0] = (a[9])%mod;
else if(i==1)b[1] = (a[0] + a[9])%mod;
else b[i] = (a[i-1])%mod;
}
for(int i=0;i<10;++i)a[i] = b[i];
}
ll ans = 0;
for(int i=0;i<10;++i){
ans = (ans + a[i])%mod;
}
//cout<<"here ";
cout<<ans<<endl;
*/
}
return 0;
}
|
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
ll mod=1000000007;
using namespace std;
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll dp[10][200001];
//ll dp[200001][10];
// void calc()
// {
// for(int i=0;i<=9;i++) dp[0][i]=1;//base case
// for(int i=1;i<=200000;i++)
// {
// for(int j=0;j<9;j++)
// dp[i][j]=dp[i-1][j+1];
// dp[i][9]=(dp[i-1][1]+dp[i-1][0])%mod;
// }
// }
ll fun(ll n,ll m)
{
//cout<<"Tej ";
if(m==0) return 1;
if(dp[n][m]!=-1) return dp[n][m];
if(n==9)
dp[n][m]=fun(1,m-1)+fun(0,m-1);
else
dp[n][m]=fun(n+1,m-1);
return dp[n][m]%mod;
}
void solve()
{
ll n,m;
cin>>n>>m;
ll ans=0;
while(n)
{
ans=(ans + fun(n%10,m))%mod;
n/=10;
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
memset(dp,-1,sizeof(dp));
//calc();
int t=1;cin>>t;
while(t--)
{
solve();
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define long long long
#define fi first
#define se second
const long MOD = 1e9+7;
const long LINF = 1e18;
const long INF = 1e9;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
int D[10][200003][10];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("input.in", "r", stdin);
for(int i = 0; i < 10; i++)
D[i][0][i] = 1;
for(int i = 0; i < 10; i++)
{
for(int j = 0; j <= 199999; j++)
{
for(int k = 0; k <= 8; k++)
D[i][j+1][k+1] = (D[i][j+1][k+1]+D[i][j][k])%MOD;
D[i][j+1][1] = (D[i][j+1][1]+D[i][j][9])%MOD;
D[i][j+1][0] = (D[i][j+1][0]+D[i][j][9])%MOD;
}
}
int t; cin >> t;
while(t--)
{
string s; cin >> s;
int k; cin >> k;
int res = 0;
for(char c : s)
{
int x = c-'0';
for(int i = 0; i <= 9; i++)
res = (res+D[x][k][i])%MOD;
}
cout << res << "\n";
}
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char a[20];
ll dp[200020];
ll cnt1[10];
ll cnt2[10];
ll mod=1e9+7;
int main()
{
cnt1[0]=1;
for(int i=1;i<=9;i++){
cnt1[i]=0;
}
dp[0]=1;
for(int i=1;i<200020;i++){
if(i%2==1){
memset(cnt2,0,sizeof(cnt2));
}else{
memset(cnt1,0,sizeof(cnt1));
}
for(int j=0;j<9;j++){
if(i%2==1){
cnt2[j+1]=cnt1[j]%mod;
}else{
cnt1[j+1]=cnt2[j]%mod;
}
}
if(i%2==1){
cnt2[0]=(cnt2[0]+cnt1[9])%mod;
cnt2[1]=(cnt2[1]+cnt1[9])%mod;
}else{
cnt1[0]=(cnt1[0]+cnt2[9])%mod;
cnt1[1]=(cnt1[1]+cnt2[9])%mod;
}
ll sum=0;
for(int j=0;j<10;j++){
if(i%2==1){
sum=(sum+cnt2[j])%mod;
}else{
sum=(sum+cnt1[j])%mod;
}
}
dp[i]=sum%mod;
}
ll t;
scanf("%lld",&t);
while(t--){
ll n,m;
memset(a,'\0',sizeof(a));
scanf("%s%lld",a,&m);
ll sum=0;
for(int i=0;i<strlen(a);i++){
sum=(sum%mod+dp[a[i]-'0'+m]%mod)%mod;
}
printf("%lld\n",sum);
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const int N = 300005;
const int mod = 1e9 + 7;
#define ll long long
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define per(i, a, b) for(int i=(a);i>=(b);--i)
#define ms(a, b) memset(a, b, sizeof a)
int n, T, m;
ll f[N + 100];
int main(){
for(int i=0;i<=9;i++)f[i]=1;
for(int i=10;i<N;i++)f[i]=(f[i-10]+f[i-9])%mod;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &m);
int ans = 0;
while(n)ans=(ans+f[m+n%10])%mod, n /= 10;
printf("%d\n", ans);
}
}
|
#include <bits/stdc++.h>
#define int long long int
#define F first
#define S second
#define MK make_pair
#define pb push_back
#define mid (l + r) / 2
using namespace std ;
const int N = 3e5 + 100 , M = 1e9 + 7;
int n , m , k , a[N] , f[10][N] , s[N] ;
int32_t main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cout << setprecision(30) << fixed ;
int ttt;
cin >> ttt;
f[0][0] = 1 ;
s[0] = 1 ;
for(int i = 1 ; i <= 3e5 ; i++){
f[0][i] = f[9][i - 1] ;
f[1][i] = f[0][i - 1] + f[9][i - 1];
f[2][i] = f[1][i - 1] ;
f[3][i] = f[2][i - 1] ;
f[4][i] = f[3][i - 1] ;
f[5][i] = f[4][i - 1] ;
f[6][i] = f[5][i - 1] ;
f[7][i] = f[6][i - 1] ;
f[8][i] = f[7][i - 1] ;
f[9][i] = f[8][i - 1] ;
f[1][i] %= M ;
f[1][i] %= M ;
f[2][i] %= M ;
f[3][i] %= M ;
f[4][i] %= M ;
f[5][i] %= M ;
f[6][i] %= M ;
f[7][i] %= M ;
f[8][i] %= M ;
f[9][i] %= M ;
s[i] = s[i - 1] + f[9][i - 1] ;
s[i] %= M ;
}
while(ttt--){
cin >> n >> m;
int ans = 0 ;
while(n){
int x = (n % 10) ;
ans += s[x + m] ;
n /= 10 ;
}
ans %= M ;
cout << ans << '\n' ;
}
}
/*
#include <radman/roderc++.h>
....._____
.~~~~~////////\\ ...
.:::::////////////\\ ....::////////.. (/\\\\...
.:::::////// \\\\///\\ .::::// ..:::::///////////////. \\\\\$$$$$$
\\\\\////// \\\\///\\ //\\\////// \\\\\////////////////////. ""\\$$$$$$$
\\\\\//// \\\\//// |||||////////. \\\\\///// ~~~~~////// ... "\$$$$
\\\\\//\ ////|||/ \\\\\///////// \\\\\//\ ~~~~~////// (/\\\\... .
\\\\\//\ ////|||/ |||||////*\\///. \\\\\//\ ~~~~~////// \\\\\$$$$$$ .@@@@@.
\\\\\//\ ////|||/ \\\\\///|\\\//// \\\\\//\ ~~~~~////// ""\\$$$$$$$ @@@@////\
\\\\\//\ ____---/|||/ |||||///|\\\\\///. \\\\\//\ ~~~~~////// "\$$$$ @@@@\///\
\\\\\//\--|||||||_-' \\\\\///|\\\\\//// \\\\\//\ ~~~~~////// ,@@@@|///|
\\\\\//\|||||_"-\\\\\ |||||///| ~~~~~///. \\\\\//\ ~~~~~////// .@@@@. /@@@@@|/////
\\\\\//\///"""\\\\\\\\ \\\\\///|~~~~[[[////. \\\\\//\ ~~~~~////// @@@@@@@@ ..@@@@@.//////
\\\\\//\ \"""\\\\\\\ |||||///|~~[[[[["\////. \\\\\//\ ~~~~~////// '@@@@/////\ .:;@@@@@@@..///////"
\\\\\//\ \"""\\\\\\ \\\\\///|[[[[*\\\\\////. \\\\\//\ ~~~~~////// *@@@\//////\@@@@@@@@..//////////"
\\\\\//\ \:::\\\\/ |||||///|[[[* \\\\\\/// \\\\\//\~~~~~///////' *@@\/////////////////////"
\\\\\//\ \___\\/ \\\\\///|* \\\\\/" \\\\\//\~~////////' **"///////////"""
\\\\\//\ |||||///| \\\\\//\///////"
\\\\\//\ \\\\\///| \\\\\//\////"
\\\\\/// |||||////| \\\\\////"
\\\\\/" \\\\\///* \\\\\/"
"""""*
*/
|
//#pragma GCC optimize("Ofast,fast-math,unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt")
#include <bits/stdc++.h>
//#define int32_t int64_t
/*
const size_t MAX_MEM = 2e8;
char MEM[MAX_MEM];
size_t MEM_POS = 0;
void* operator new(size_t x) {
auto ret = MEM + MEM_POS;
MEM_POS += x;
assert(MEM_POS < MAX_MEM);
return ret;
}
void operator delete(void*)
{}
*/
template <class T>
std::istream& operator>>(std::istream &in, std::vector<T> &a) {
for (auto &x : a)
in >> x;
return in;
}
template <class T>
std::ostream& operator<<(std::ostream &out, const std::vector<T> &a) {
for (auto &x : a)
out << x << " ";
return out;
}
template <class T, class U>
std::istream& operator>>(std::istream &in, std::pair<T, U> &p) {
in >> p.first >> p.second;
return in;
}
template <class T, class U>
std::ostream& operator<<(std::ostream &out, const std::pair<T, U> &p) {
out << p.first << " " << p.second;
return out;
}
const int64_t P = 1e9+7;
int64_t add(int64_t a, int64_t b) {
return a + b >= P ? a + b - P : a + b;
}
int64_t mul(int64_t a, int64_t b) {
return a * b % P;
}
const int64_t M = 2e5+5, D = 10;
std::vector<std::vector<int64_t>> dp(M, std::vector<int64_t>(D));
void init() {
for (int i = 0; i < D; ++i)
dp[0][i] = 1;
for (int l = 1; l < M; ++l) {
for (int d = 0; d < D; ++d) {
if (d == 9) {
dp[l][d] = add(dp[l - 1][0], dp[l - 1][1]);
} else {
dp[l][d] = dp[l - 1][d + 1];
}
}
}
}
void solve() {
int64_t m;
std::string n;
std::cin >> n >> m;
std::reverse(n.begin(), n.end());
while (n.size() > 1 && n.back() == '0')
n.pop_back();
std::reverse(n.begin(), n.end());
int64_t ans = 0;
for (char d : n)
ans = add(ans, dp[m][d - '0']);
std::cout << ans << "\n";
}
signed main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
init();
int32_t t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include<iostream>
#include<stack>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<functional>
#include<limits.h>
#include<utility>
#include<queue>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<bitset>
#include<time.h>
#include<unordered_map>
#define lowbit(x) ((x)&(-x))
typedef long long ll;
typedef long double ld;
using namespace std;
//
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9+7;
const double eps = 1e-7;
typedef pair<ll, ll> pii;
int dir[4][2] = { {0,1},{0,-1},{-1,0},{1,0} };
ll dp[10][maxn];
ll dfs(int now, int re)
{
if (re == 0) return 1;
if (dp[now][re]) return dp[now][re];
ll ans = 0;
if (now + re >= 10)
{
ans = dfs(1, re - 10 + now) + dfs(0, re - 10 + now);
ans %= mod;
}
else
ans = dfs(now + re, 0);
return dp[now][re] = ans;
}
string s;
int m;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--)
{
cin >> s >> m;
ll ans = 0;
for (int i = 0; i < s.size(); i++)
ans += dfs(s[i] - '0', m), ans %= mod;
cout << ans << endl;
}
return ~~(0 - 0);
}
|
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M = 1e9+7;
ll mod(ll x){
return (x%M + M)%M;
}
ll mul(ll a, ll b){
return mod((mod(a)*mod(b)));
}
ll add(ll a , ll b){
return mod(mod(a)+mod(b));
}
void solve(){
vector<vector<int>>dp(200001,vector<int>(10));
for(int i=0;i<10;i++) dp[0][i]=1;
for(int i=1;i<=200000;i++){
for(int j=0;j<10;j++){
if(j<=8) dp[i][j]=dp[i-1][j+1];
else dp[i][j]=add(dp[i-1][0],dp[i-1][1]);
}
}
int t;
cin>>t;
while(t--){
string s;
cin>>s;
int m;
cin>>m;
vector<int>f(10,0);
for(auto i : s) f[i-'0']++;
ll ans=0;
for(int i=0;i<10;i++){
ans=add(ans,mul(f[i],dp[m][i]));
}
cout<<ans<<"\n";
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout<<fixed;
cout<<setprecision(10);
// freopen("timber_input.txt", "r", stdin);
// freopen("timber_output.txt", "w", stdout);
int t=1;
// cin>>t;
for(int i=1;i<=t;i++){
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
}
|
// Problem: C. Add One
// Contest: Codeforces - Divide by Zero 2021 and Codeforces Round #714 (Div. 2)
// URL: https://codeforces.com/contest/1513/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<iostream>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int N = 2e5+10;
const int mod = 1e9+7;
long long a[15];
long long b[N];
void init(){
for(int i = 0; i <= 8; i ++) b[i] = 2;
b[9]=3;
for(int i = 10; i <=200005;i++) b[i] = (b[i-9]+b[i-10])%mod;
}
void solve(long long m,long long n){
for(int i = 0; i <=9;i ++) a[i] = 0;
// long long n, m;
// cin >> n >> m;
long long ans = 0;
if(n==0) {
a[0]++;
}
while(n){
a[n%10]++;
n/=10;
}
for(int i = 0; i <=9; i ++){
long long x;
if(m-10+i<0) x = 1;
else x = b[m-10+i];
long long temp = (a[i]*x)%mod;
ans+=temp;
ans%=mod;
}
printf("%lld\n",ans);
return;
}
int main(){
int T;
cin >> T;
init();
while (T--){
long long n, m;
scanf("%lld %lld",&n,&m);
solve(m,n);
}
// for(int i = 0; i <= 100; i ++){
// cout <<"i="<<i<<"----";
// solve(i,10);
// }
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ifs freopen("aa.in","r",stdin);
#define ofs freopen("aa.out","w",stdout);
#define iof ifs ofs
#define ll long long
#define ld long double
#define da(x,i) cout << #x << "[" << i << "]=" << x[i] << "\n";
#define da2(x,i,y,j) cout << #x << "[" << i << "]=" << x[i] << " ! " << #y << "[" << j << "]=" << y[j] << "\n";
#define d2a(x,i,j) cout << #x << "[" << i << "][" << j << "]=" << x[i][j] << "\n";
#define db(x) cout << #x << "=" << (x) << "\n";
#define db2(x,y) cout << #x << "=" << (x) << " ! " << #y << "=" << (y) << "\n";
#define db3(x,y,z) cout << #x << "=" << (x) << " ! " << #y << "=" << (y) << " ! " << #z << "=" << (z) << "\n";
#define db4(w,x,y,z) cout << #w << "=" << (w) << " ! " << #x << "=" << (x) << " ! " << #y << "=" << (y) << " ! " << #z << "=" << (z) << "\n";
#define inf LLONG_MAX
#define fr first
#define sc second
#define all(a) a.begin(),a.end()
const ll N=2e5+70, M=1e9+7;
ll f[N];
ll tt,i,n,m,d,A;
string s;
int main()
{
fastio
for(i=0; i<10; i++)
f[i]=1;
for(i=10; i<N; i++)
f[i]=(f[i-10]+f[i-9])%M;
cin>>tt;
while(tt--){
cin>>n>>m;
for(i=n,A=0; i; i/=10){
d=i%10; d+=m;
A=(A+f[d]+M)%M;
}
cout<< A <<"\n";
}
}
|
//Bismillahir Rahmanir Raheem
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
ll dp[200001][11];
ll f(ll m,ll x){
if(m==0)return 0;
if(dp[m][x]!=-1)return dp[m][x];
dp[m][x]=0;
if(m>=(10-x)){
dp[m][x]=(1+(f(m-(10-x),0))%mod+(f(m-(10-x),1))%mod)%mod;
}
return dp[m][x];
}
int main()
{
fast;
memset(dp,-1,sizeof(dp));
f(200001,0);
f(200001,1);
int t;
cin>>t;
while(t--)
{
ll n,m;
string s;
cin>>s>>m;
ll ans=0;
n=s.size();
for(int i=0;i<n;i++){
ll v=s[i]-'0';
ans=(ans+1+f(m,v))%mod;
}
cout<<ans<<endl;
}
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
/*
find my code templates at https://github.com/galencolin/cp-templates
also maybe subscribe please thanks
*/
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL);}
#define f first
#define s second
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
cin >> p.first;
return cin >> p.second;
}
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 rng(61378913);
/* usage - just do rng() */
void usaco(string filename) {
// #pragma message("be careful, freopen may be wrong")
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
// #include <atcoder/all>
// using namespace atcoder;
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;
ll n, m, q, k, l, r, x, y, z;
const ll template_array_size = 1e6 + 15075;
ll a[template_array_size];
ll b[template_array_size];
ll c[template_array_size];
string s, t;
ll ans = 0;
ll dp[200005][11];
void solve(int tc = 0) {
cin >> s >> m;
ll ans = 0;
for (char c: s) ans = (ans + dp[m][c - '0']) % mod;
cout << ans << '\n';
}
int main() {
#ifdef galen_colin_local
auto begin = std::chrono::high_resolution_clock::now();
#endif
send help
#ifndef galen_colin_local
// usaco("code");
#endif
// usaco("cowland");
// freopen("tc.cpp", "r", stdin);
// freopen("tc2.cpp", "w", stdout);
cout << setprecision(15) << fixed;
memset(dp, 0, sizeof(dp));
for (ll i = 0; i < 10; i++) dp[0][i] = 1;
for (ll i = 1; i <= 200003; i++) {
for (ll j = 0; j < 9; j++) {
dp[i][j] = dp[i - 1][j + 1];
}
dp[i][9] = (dp[i - 1][1] + dp[i - 1][0]) % mod;
}
int tc = 1;
cin >> tc;
for (int t = 0; t < tc; t++) solve(t);
#ifdef galen_colin_local
auto end = std::chrono::high_resolution_clock::now();
cerr << setprecision(4) << fixed;
cerr << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
#endif
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N=1e9+7;
#define int long long
#define pb push_back
#define f first
#define si second
#define mp make_pair
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define PI 3.1415926535897
string alp="abcdefghijklmnopqrstuvwxyz";
signed main(){
fastrack;
int test=1;
cin>>test;
map<int,int>m[2];
int d[2][200007];
for(int i=0;i<2;i++){
for(int j=0;j<200007;j++){
d[i][j]=0;
}
}
for(int i=0;i<2;i++){
for(int j=0;j<10-i;j++){
d[i][j]=1;
}
m[i][10-i]=1;
d[i][10-i]=2;
for(int j=11-i;j<200007;j++){
d[i][j]+=(d[i][j-1]%N+m[i][j-9]%N+m[i][j-10]%N)%N;
d[i][j]%=N;
m[i][j]=N+(d[i][j])-(d[i][j-1]);
m[i][j]%=N;
}
}//cout<<d[9][200000]<<endl;
while(test--){
int n,m,x,ans=0;
cin>>n>>m;
int c[10]={};
while(n>0){
x=n%10;
c[x]++;
n/=10;
}
for(int i=0;i<10;i++){
if(i==0||i==1){
ans+=(c[i]*d[i][m])%N;
ans%=N;
}
else{
if(m>=10-i){
ans+=(c[i]*d[0][m-10+i])%N;
ans%=N;
ans+=(c[i]*d[1][m-10+i])%N;
ans%=N;
}
else if(c[i]){
ans+=c[i];
ans%=N;
}
}
//cout<<ans<<" ";
}//cout<<endl;
cout<<ans<<endl;
}
}
|
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
os << "]";
return os;
}
template <class T> ostream &operator<<(ostream &os, set<T> S) {
os << "{ ";
for (auto s : S)
os << s << " ";
return os << "}";
}
template <class T> ostream &operator<<(ostream &os, multiset<T> S) {
os << "{ ";
for (auto s : S)
os << s << " ";
return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
os << "{ ";
for (auto m : M)
os << "(" << m.first << ":" << m.second << ") ";
return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
const int M = 200050;
int res[M];
void solve() {
int n, m;
cin >> n >> m;
int num = n;
int ans = 0;
while(num) {
ans += res[num % 10 + m - 1];
num /= 10;
ans %= MOD;
}
cout << ans << endl;
}
int32_t main() {
int t = 1;
#ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<int> count(10, 0);
count[0] = 1;
for(int i = 0; i < M; i++) {
vector<int> temp(10, 0);
temp[0] = count[9];
for(int j = 0; j < 9; j++) {
temp[j + 1] = count[j];
}
temp[1] += temp[0];
temp[1] %= MOD;
int sum = 0;
for(int j = 0; j < 10; j++) {
count[j] = temp[j];
sum += count[j];
sum %= MOD;
}
res[i] = sum;
}
cin >> t;
while(t--) {
solve();
}
#ifndef ONLINE_JUDGE
cout << "\nTime Elapsed : " << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC << " ms\n";
#endif
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define pb push_back
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define min3(a,b,c) min(min((a),(b)),(c))
#define min4(a,b,c,d) min(min((a),(b)),min((c),(d)))
#define all(v) (v).begin(),(v).end()
#define endl "\n"
#define pii pair<int,int>
ll mod =1e9 +7;
ll power(ll x,int y, int p)
{
ll res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
ll modInverse(ll n,int p)
{
return power(n, p - 2, p);
}
ll ncr(ll n,int r, int p) //Combination
{
if (n < r)
return 0;
if (r == 0)
return 1;
unsigned long long fac[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = (fac[i - 1] * i) % p;
return (fac[n] * modInverse(fac[r], p) % p
* modInverse(fac[n - r], p) % p)% p;
}
int gcd(int a,int b) //gcd function
{
if(b==0)
return a;
else return gcd(b,a%b);
}
ll _ceil(ll a,ll b) //ceil
{
if(a%b==0) return a/b;
else return a/b+1;
}
int _pow(int a, int b){
if(!b)
return 1;
int temp = _pow(a, b / 2);
temp = (temp * temp);
if(b % 2)
return (a * temp);
return temp;
}
bool isPrime(int n) //Check Prime
{
if (n <= 1) return false;
if (n <= 3) return true;
if (n%2 == 0 || n%3 == 0) return false;
for (int i=5; i*i<=n; i=i+6)
if (n%i == 0 || n%(i+2) == 0)
return false;
return true;
}
int mx = 2e5 +5;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios
vector<ll> dp(mx,2);
dp[9]=3;
for(int i=10;i<mx;i++)
{
dp[i] = (dp[i-9]%mod+dp[i-10]%mod)%mod;
}
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
ll sum =0;
while(n>0)
{
int d = n%10;
if(d+k<10)
sum++;
else
{
sum+=dp[d+k-10]%mod;
}
sum%=mod;
n/=10;
}
cout<<sum<<endl;
}
}
|
#include <iostream>
const int MOD = 1e9 + 7;
const int MX = 2e5 + 55;
int memo[MX + 1];
int d[10];
int main() {
std::ios_base::sync_with_stdio(0); std::cin.tie(0);
int t = 1; scanf("%d", &t);
d[0] = 1;
for (int i = 1; i <= MX; i++) {
int tmp[10] = { 0 };
for (int j = 0; j <= 9; j++) {
if (j == 9) {
tmp[1] = (tmp[1] + d[j]) % MOD;
tmp[0] = (tmp[0] + d[j]) % MOD;
} else {
tmp[j + 1] = d[j];
}
}
for (int j = 0; j <= 9; j++) {
d[j] = tmp[j];
memo[i] = (memo[i] + d[j]) % MOD;
}
}
while (t--) {
int n, m; scanf("%d%d", &n, &m);
int ans = 0;
while (n) {
ans = (ans + memo[m + n % 10]) % MOD;
n /= 10;
}
printf("%d\n", ans);
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define DONTSYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now!
#define TEST unsigned long long T; cin>>T; while(T--) //loop over each testcase
#define endl "\n"
#define fori(a,start,end) for(int a=start;a<end;a++)
#define forll(a,start,end) for(long long a=start;a<end;a++)
#define forull(a,start,end) for(unsigned long long a=start;a<end;a++)
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const double PI = acos(-1);
int mod=1e9+7;
void solve(vl &dp){
/* code */
ll res=0;
ll n; int m; cin>>n>>m;
while(n){
int d=n%10;
n/=10;
res=(1+res+dp[d+m])%mod;
}
cout<<res<<endl;
}
int main()
{
DONTSYNC;
int MX=2e5+20;
vl dp(MX,0); dp[10]=1;
fori(i,0,MX){
if(dp[i] && i+9<MX){
dp[i+9]=(dp[i+9]+dp[i])%mod;
}
if(dp[i] && i+10<MX){
dp[i+10]=(dp[i+10]+dp[i])%mod;
}
if(i){
dp[i]=(dp[i]+dp[i-1])%mod;
}
}
TEST
solve(dp);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#ifndef _LOCAL
//#pragma GCC optimize("O3,Ofast")
#else
#pragma GCC optimize("O0")
#endif
#define ttt template<typename t, typename u>
ttt inline void umin(t &a, const u b) {if(b < a) a = b;}
ttt inline void umax(t &a, const u b) {if(a < b) a = b;}
ttt vector<t>& operator<< (vector<t> &a, const u b) {a.push_back(t(b)); return a;}
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef int8_t byte;
ll time() {return chrono::system_clock().now().time_since_epoch().count();}
mt19937 rnd(time());
#define ft first
#define sd second
#define len(f) int((f).size())
#define bnd(f) (f).begin(), (f).end()
#define _ <<' '<<
const int inf = 1e9 + 5;
const ll inf64 = 4e18 + 5;
const int md = 1e9 + 7;
namespace MD {
void add(int &a, const int b) {if((a += b) >= md) a -= md;}
void sub(int &a, const int b) {if((a -= b) < 0) a += md;}
int prod(const int a, const int b) {return ll(a) * b % md;}
};
const int N = 2e5 + 5;
int f[10][N][10];
bool ready;
void solve() {
if(!ready) {
ready = true;
for(int d = 0; d < 10; ++d) {
f[d][0][d] = 1;
for(int i = 1; i < N; ++i) {
for(int j = 1; j < 10; ++j)
MD::add(f[d][i][j], f[d][i - 1][j - 1]);
MD::add(f[d][i][0], f[d][i - 1][9]);
MD::add(f[d][i][1], f[d][i - 1][9]);
}
}
}
int n, m;
cin >> n >> m;
int ans = 0;
vector<int> t;
if(!n) t << 0;
while(n) t << n % 10, n /= 10;
for(int i : t)
for(int j = 0; j < 10; ++j)
MD::add(ans, f[i][m][j]);
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef _LOCAL
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
#else
system("color a");
freopen("in.txt", "r", stdin);
#endif
int t; cin >> t;
while(t--)
solve();
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
const int N = 2e5 + 5, M = 1e9 + 7;
vector<vector<int>> dp;
void pre() {
dp = vector<vector<int>> (N, vector<int> (10, 1));
for(int i = 1 ; i < N ; i++) {
for(int j = 0 ; j < 9 ; j++) {
dp[i][j] = dp[i - 1][j + 1];
}
dp[i][9] = (dp[i - 1][0] + dp[i - 1][1]) % M;
}
}
void solve() {
int res = 0;
int n, m;
cin >> n >> m;
while(n) {
res = (res + dp[m][n % 10]) % M;
n /= 10;
}
cout << res << "\n";
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
pre();
cin >> t;
while(t--)
solve();
return 0;
}
|
/**
* author : madhav
* handle : madhav10
**/
#include <bits/stdc++.h>
using namespace std;
#define For(start,end,inc) for( int i=(start);i<(end);i+=inc)
typedef long long ll;
int nax=1e6+15;
vector<ll> f(nax,0);
vector<ll> num(10,0);
ll convert(){
int mod=1e9+7;
vector<ll> tmp(10,0);
For(1,10,1){
tmp[i]=num[i-1];
}
tmp[0]=(num[9])%mod;
tmp[1]=(tmp[1]+num[9])%mod;
ll ans=0;
For(0,10,1){
ans=(ans+tmp[i])%mod;
num[i]=tmp[i];
}
return ans;
}
void solve(){
int n,m,mod=1e9+7;
cin>>n>>m;
ll ans=0;
while(n>0){
int tmp=n%10;
ans=(ans+f[m+tmp])%mod;
n=n/10;
}
cout<<ans<<"\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
f[0]=1;
num[0]=1;
For(1,nax,1){
f[i]=convert();
//cout<<f[i]<<" ";
}
cin>>T;
while(T--){
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#include<sstream>
#include<string>
#include<vector>
#include <set>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
long long M=1000000007;
using namespace std;
ll fact[10000];
ll m1[2000001][10];
ll power(ll x, unsigned ll y, unsigned ll m)
{
if (y == 0)
return 1;
ll p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
unsigned long long modInverse(unsigned long long n,
ll p)
{
return power(n, p - 2, p);
}
unsigned long long nCrModPFermat(unsigned long long n,
ll r, ll p)
{
// If n<r, then nCr should return 0
if (n < r)
return 0;
// Base case
if (r == 0)
return 1;
return (fact[n] * modInverse(fact[r], p) % p
* modInverse(fact[n - r], p) % p)
% p;
}
int32_t main()
{
IOS
for(ll j=0;j<=9;j++)m1[0][j]=1;
for(ll i=1;i<=200000;i++)
{
for(ll j=0;j<=9;j++)
{
if(j==9)
{
m1[i][j]=(m1[i-1][1]+m1[i-1][0])%M;
}
else
m1[i][j]=m1[i-1][j+1];
}
}
ll t;
cin>>t;
while(t--)
{
ll n,m;
cin>>n>>m;
ll cnt=0;
while(n>0)
{
cnt+=(m1[m][n%10])%M;
cnt%=M;
n/=10;
}
cout<<cnt<<endl;
}
return 0;
}
|
/*...................................................................*
*............___..................___.....____...______......___....*
*.../|....../...\........./|...../...\...|.............|..../...\...*
*../.|...../.....\......./.|....|.....|..|.............|.../........*
*....|....|.......|...../..|....|.....|..|............/...|.........*
*....|....|.......|..../...|.....\___/...|___......../....|..___....*
*....|....|.......|.../....|...../...\.......\....../.....|./...\...*
*....|....|.......|../_____|__..|.....|.......|..../......|/.....\..*
*....|.....\...../.........|....|.....|.......|.../........\...../..*
*..__|__....\___/..........|.....\___/...\___/.../..........\___/...*
*...................................................................*
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1000000000000000000
const int M = 200005;
const int MOD = 1000000007;
int dp[10][M];
int recur(int d,int m)
{
if(m==0)
{
dp[d][m]=1;
return 1;
}
if(dp[d][m]!=-1)
{
return dp[d][m];
}
if(d==9)
{
dp[d][m]=(recur(0,m-1)+recur(1,m-1))%MOD;
}
else
{
dp[d][m]=recur(d+1,m-1);
}
return dp[d][m];
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
memset(dp,-1,sizeof(dp));
for(int i=0;i<10;i++)
{
for(int j=0;j<M;j++)
{
if(dp[i][j]==-1)
recur(i,j);
}
}
int tt=1;
cin >> tt;
while(tt--)
{
int n,m;
cin >> n >> m;
int ans=0;
while(n>0)
{
int d=n%10;
ans=(ans+dp[d][m])%MOD;
n=n/10;
}
cout << ans << '\n';
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MOD 1000000007
#define fi first
#define se second
#define rep(i,n) for(ll i = 0 ; i < n ; i++)
#define repe(i,n) for(ll i = 0 ; i <= n ; i++)
#define repb(i,a,b) for(ll i = a ; i < b ; i++)
#define repeb(i,a,b) for(ll i = a ; i <= b ; i++)
#define rfor(i,n,a) for(ll i = n ; i >= a ; i--)
#define pb push_back
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair <ll,ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a,b) cout << a << " " << b << endl
#define watch(x) cout << (#x) << " is " << (x) << endl
#define w(x) ll x; cin>>x; while(x--)
template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
{
return os << "(" << p.first << ", " << p.second << ")";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
{
bool first = true;
os << "[";
for(unsigned int i = 0; i < v.size(); i++)
{
if(!first)
os << ", ";
os << v[i];
first = false;
}
return os << "]";
}
/*-------------------------------------------------*/
// read once, read again, think, code
const ll MAXM = 2e5+1;
ll cnt[10][MAXM][10];
void solve() {
string s; ll m, ans = 0;
cin >> s >> m;
for(char c : s) {
int digit = c-'0';
for(int end = 0 ; end < 10 ; end++) {
ans = (ans + cnt[digit][m][end]) % MOD;
}
}
p1(ans);
}
int main()
{
fastio;
#ifndef ONLINE_JUDGE
freopen("/home/devang/input.txt","r",stdin);
freopen("/home/devang/output.txt","w",stdout);
#endif
memset(cnt,0,sizeof(cnt));
for(int src = 0 ; src < 10 ; src++) {
cnt[src][0][src] = 1;
for(ll op = 1 ; op < MAXM ; op++) {
for(int dest = 0 ; dest < 10 ; dest++) {
if(dest == 0) {
cnt[src][op][dest] = cnt[src][op-1][9];
} else if(dest == 1) {
cnt[src][op][dest] = (cnt[src][op-1][0] + cnt[src][op-1][9]) % MOD;
} else {
cnt[src][op][dest] = cnt[src][op-1][dest-1];
}
}
}
}
w(tc)
solve();
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define for0() for(int i = 0; i < n; i++)
#define for1() for(int i = 1; i < n; i++)
#define forv(c, k) for(int i = c; i < k; i++)
#define vi vector<int>
#define endl '\n'
#define mod 1000000007
using namespace std;
int dp[12][200010];
int main()
{
cin.tie(NULL);
ios_base::sync_with_stdio(false);
for(int i = 0; i < 10; i++)
{
dp[i][0] = 1;
}
for(int i = 1; i < 200002; i++)
{
for(int j = 0; j < 10; j++)
{
if(j == 9)
{
dp[j][i] = (dp[1][i-1] + dp[0][i-1])%mod;
break;
}
dp[j][i] = dp[j+1][i-1];
}
}
ll t, n, m, p, q, temp; cin >> t;
while(t--)
{
cin >> n >> m;
ll ans = 0;
int nums;
while(n)
{
nums = n%10; n/=10;
ans = (ans + dp[nums][m])%mod;
}
cout << ans << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
// DATA TYPES
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
// FUNCTIONS
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin
#define I insert
#define E erase
#define LB lower_bound
#define UB upper_bound
#define P pair
// DS
#define UMAP unordered_map
#define USET unordered_set
#define V vector
#define PQ priority_queue
#define DQ deque
// LOOPS
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORR(i,a,b) for(ll i=a;i>=b;i--)
// MOD
#define MOD_MUL(a,b) ((a%MOD) * (b%MOD))%MOD
#define MOD_ADD(a,b) ((a%MOD) + (b%MOD))%MOD
#define MOD_SUB(a,b) ((a%MOD) - (b%MOD))%MOD
#define MOD 1000000007
// GRAPH
map<ll,V<ll>>g;
map<ll,bool>g_visited;
map<ll,ll>g_parient;
map<ll,ll>g_distance;
void dfs(ll s){ g_visited[s] = true; for(auto x:g[s]) if(!g_visited.count(x)) dfs(x);}
ll dijkitras(ll s,ll e){PQ<P<ll,ll>>ss; ss.push({0,s});g_distance[s] = 0; g_parient[s] = -1; ll ans = -1; while(!ss.empty()){auto x = ss.top(); ss.pop(); ll d = -x.first, ver = x.second;if(ver==e){ ans = d;break;}for(auto a:g[ver])if( !g_distance.count(a) or g_distance[a]>1+g_distance[ver]){ss.push({-(d+1),a});g_distance[a] = d+1;g_parient[a] = ver;}}return ans;}
V<ll> g_dijkistra_traversal(ll s,ll e){ll a = e;V<ll>v;while(a!=s){v.PB(a);a = g_parient[a];} v.PB(a);ll g_n = v.size();FORR(i,v.size()/2,0) swap(v[i],v[g_n-1-i]); return v;}
#define COUNT1(x) __builtin_popcountll(x)
#define COUNT0(x) __builtin_ctzll(x)
// extended_euclidian => ax + by = gcd(a,b)
// diophentane => ax + by = c [ condition c%gcd == 0 ]
// modulo_inverse => (a*x)%m = 1 => ax + my = 1
ll euclid(ll a,ll b){
if(b==0) return a;
return euclid(b,a%b);
}
tuple<ll,ll,ll> euclidian_theorem(ll a, ll b){
if(b==0){
return {a,1,0};
}
ll g,x,y;
tie(g,x,y) = euclidian_theorem(b,a%b);
return {g,y,x - ((a*y)/b)};
}
pair<ll,ll> diophentane(ll a,ll b,ll c){
ll g = euclid(a,b);
ll x,y;
if(c%g!=0) return {0,0};
tie(g,x,y) = euclidian_theorem(a,b);
ll k = c/g;
x = x*k;
y = y*k;
return {x,y};
}
ll modulo_inverse(ll a,ll m){
ll g,x,y;
tie(g,x,y) = euclidian_theorem(a,m);
if(g!=1) return 0;
x = (x%m + m)%m;
return x;
}
ll chinese_remainder_theorem(vector<ll>a, vector<ll>m){
ll ans = 0;
ll n = m.size();
// pair gcd check
for (ll i = 0; i < n; ++i) for (ll j = i+1; j < n; ++j) if(euclid(m[i],m[j])!=1) return 0;
ll mul_m = 1; for (int i = 0; i < n; ++i) mul_m *= m[i];
for(ll i=0;i<n;i++){
ll mk = mul_m/m[i];
ll xk = a[i]*mk*modulo_inverse(mk,m[i]);
ans += xk;
}
return ans%mul_m;
}
#define N 200001
ll all[N][10];
void fill_all(){
FOR(i,0,9){
all[0][i] = 1;
}
FOR(i,1,N-1){
FOR(j,0,8)
all[i][j] = all[i-1][j+1];
all[i][9] = all[i-1][0] + all[i-1][1];
all[i][9] %= MOD;
}
}
void solve(){
ll n,m; cin>>n>>m;
ll ans =0;
while(n){
ans = MOD_ADD(ans,all[m][n%10]);
n/=10;
}
cout<<ans<<"\n";
}
int main(){
// for faster input
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cout<<"code is running ;)\n";
fill_all();
ll t; cin>>t; while(t--)
solve();
return 0;
}
|
#include<bits/stdc++.h>
#include<string>
#include<map>
#include<set>
#include<sstream>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define linebreak cout<<"\n"
#define lli long long int
const int MOD = 1000000007;
const int N = 100005;
const lli p = 53;
const lli m = 1000000000000000009;
int dx[] = {-1,-1,-1,0,0,1,1,1};
int dy[] = {-1,0,1,-1,1,-1,0,1};
int dappa[2][200010];
int dp(int n, int m) {
// cout << n << " " << m << "\n";
if(dappa[n][m] != 0) { return dappa[n][m]; }
if(m < 9) { dappa[n][m] = 1; return 1; }
if(n == 0 && m < 10) { dappa[n][m] = 1; return 1; }
if(n == 1) {
// cout << "jjj";
dappa[n][m] = (dp(1, m-9)%MOD +dp(0, m-9)%MOD)%MOD;
// cout << n << " " << m << " " << dappa[n][m] << "\n";
}
else {
// cout << "lll";
dappa[n][m] = (dp(1, m-10)%MOD +dp(0, m-10)%MOD)%MOD;
// cout << n << " " << m << " " << dappa[n][m] << "\n";
}
return dappa[n][m];
}
void testCase() {
int n, m; cin >> n >> m;
int answer = 0;
// memset(dappa, -1, sizeof(dappa));
int nn = n, mm = m;
while(nn != 0) {
mm = m;
int x = nn%10;
if(x == 0) { mm--; }
else {
mm += x-1;
}
answer = (answer+dp(1, mm))%MOD;
// cout << dappa[1][mm] << " " << x << " " << answer << " " << mm << " " << "ouch\n";
nn /= 10;
}
cout << answer << "\n";
}
int main() {
fast;
int t=1; cin >> t;
while(t!=0) {t--;
testCase();
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define take ll a[n]; for(int i=0;i<n;i++){cin>>a[i];}
#define ll long long int
#define output for (int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define vv vector<ll>
#define VIN(a) for(auto &it:a) cin>>it;
#define pb push_back
#define CIN(x,i,a,b) for(int i=a;i<b;i++){cin>>x[i];}
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define se(a) a.begin(),a.end()
#define ppi vector<pair <ll,ll>>
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
#define Endl endl;
#define DP(n,w) int dp[n+1][w+1]; memset(dp, 0, sizeof(dp));
#define INIT int t[200005]; memset(t,-1,sizeof(t));
#define INITDP int t[200005][200005]; memset(t,-1,sizeof(t));
#define mem(a,x) memset(a,x,sizeof(a));
ll dp[200001];
void solve()
{
ll n,m;
cin>>n>>m;
ll ans=0;
while(n>0)
{
ll x=n%10;
if(x+m<10)
{
ans+=1;
}
else
{
ans+=dp[x+m-10];
}
ans%=MOD;
n/=10;
}
cout<<ans<<endl;
}
int main()
{
fast
for(int i=0;i<9;i++)
{
dp[i]=2;
}
dp[9]=3;
for(int i=10;i<200001;i++)
{
dp[i]=(dp[i-9]+dp[i-10])%MOD;
}
int q=1; cin >> q; while(q--){ solve();}
}
|
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define sc second
#define pb push_back
#define ll long long
#define trav(v,x) for(auto v:x)
#define all(x) (x).begin(), (x).end()
#define VI vector<int>
#define VLL vector<ll>
using namespace std;
const int N = 1e6 + 100;
const ll mod = 1e9 + 7;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
VI mx(n + 1);
for(int i = 1; i <= n; i++)
cin >> mx[i];
VI b(n + 1);
for(int i = 1; i < n; i++)
cin >> b[i], b[i] += b[i - 1];
for(int i = 1; i < n; i++)
b[i] += b[i - 1];
vector<VLL> dp(n + 1, VLL(10010, 0));
// VLL ans(300);
ll ans = 0;
int x;
cin >> x;
cin >> x;
// for(int x = -101; x <= 101; x++)
{
dp[0][0] = 1;
int suma = 0;
for(int i = 1; i <= n; i++)
{
fill(all(dp[i]), 0);
for(int val = 0; val <= mx[i]; val++)
{
int mn = b[i - 1] + x * i - val;
mn = max(mn, 0);
for(int bf = mn; bf <= suma; bf++)
{
dp[i][val + bf] += dp[i - 1][bf];
if(dp[i][val + bf] >= mod)dp[i][val + bf] -= mod;
}
}
suma += mx[i];
}
// ans[x + 110] = 0;
// for(int i = 0; i <= suma; i++)
// {
// ans[x + 110] += dp[n][i];
// if(ans[x + 110] >= mod)ans[x + 110] -= mod;
// }
ans = 0;
for(int i = 0; i <= suma; i++)
{
ans+= dp[n][i];
if(ans >= mod)ans -= mod;
}
cout << ans << '\n';
}
// int tt;
// cin >> tt;
// while(tt --)
// {
// int x;
// cin >> x;
// x = max(x, -101);
// x = min(x, 101);
// cout << ans[x + 110] << '\n';
// }
}
|
#include<iostream>
#include<cstdio>
#include<unordered_map>
using namespace std;
const int N=105;
const int MOD=1000000007;
int n,q;
int c[N];
int b[N];
int sb[N],sc[N];
int l,r;
int solve(int x)
{
static int f[N][N*N],g[N][N*N];
f[0][0]=g[0][0]=1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<max(i*x+sb[i-1],0);j++)
f[i][j]=0;
for(int j=max(i*x+sb[i-1],0);j<=sc[i];j++)
f[i][j]=((long long)g[i-1][j-max(j-sc[i-1],0)]-(j-min(c[i],j)-1>=0?g[i-1][j-min(c[i],j)-1]:0)+MOD)%MOD;
g[i][0]=f[i][0];
for(int j=1;j<=sc[i];j++)
g[i][j]=(g[i][j-1]+f[i][j])%MOD;
}
int ans=0;
for(int j=0;j<=sc[n];j++)
ans=(ans+f[n][j])%MOD;
return ans;
}
unordered_map<int,int>res;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&c[i]);
for(int i=1;i<n;i++)
scanf("%d",&b[i]);
for(int i=1;i<n;i++)
sb[i]=sb[i-1]+b[i];
for(int i=1;i<n;i++)
sb[i]+=sb[i-1];
for(int i=1;i<=n;i++)
sc[i]=sc[i-1]+c[i];
r=(sc[n]-sb[n-1])/n;
for(int i=1;i<n;i++)
r=min(r,(sc[i]-sb[i-1])/i);
l=-sb[n-1]/n;
for(int i=1;i<n;i++)
l=min(l,sb[i-1]/i);
for(int i=l;i<=r;i++)
res[i]=solve(i);
int pw=1;
for(int i=1;i<=n;i++)
pw=1LL*pw*(c[i]+1)%MOD;
scanf("%d",&q);
while(q--)
{
int x;
scanf("%d",&x);
if(x<l) printf("%d\n",pw);
else if(x>r) printf("%d\n",0);
else printf("%d\n",res[x]);
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.