QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#377794 | #7996. 报数 IV | Destiny# | RE | 4ms | 40748kb | C++17 | 6.1kb | 2024-04-05 17:56:39 | 2024-04-05 17:56:40 |
Judging History
answer
#include<bits/stdc++.h>
#ifndef xxx
#define dbg(...) ;
#endif
using namespace std;
template<class T> ostream &operator<<(ostream &o, const vector <T> &v) { bool f=false; for(T i:v) { f?o<<' ':o; o<<(i); f=true; } return o; }
template<class T> void sort(T &v) { std::sort(v.begin(), v.end()); }
template<class T, class C> void sort(T &v, C c) { std::sort(v.begin(), v.end(), c); }
template<class T> void reverse(T &v) { std::reverse(v.begin(), v.end()); }
template<class T> bool is_sorted(T &v) { return std::is_sorted(v.begin(), v.end()); }
template<class T> inline void _min(T &x, const T &y) { x>y?x=y:x; }
template<class T> inline void _max(T &x, const T &y) { x<y?x=y:x; }
istream &operator>>(istream &i, __int128_t &x) { x=0; short f=1; char c=0; while(!isdigit(c)) { if(c=='-')f=-1; c=i.get(); } while(isdigit(c))x=x*10+c-'0', c=i.get(); x*=f; return i; }
ostream &operator<<(ostream &o, __int128_t x) { if(x==0) { o<<0; return o; } bool f=false; string s; if(x<0)f=true, x=-x; while(x)s+=x%10+'0', x/=10; reverse(s); if(f)o<<'-'; o<<s; return o; }
mt19937 mt(time(0));
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
constexpr int maxn=1e4+5;
constexpr int mod=1e9+7;
constexpr int inf=0x3f3f3f3f;
constexpr ll INF=0x3f3f3f3f3f3f3f3fll;
constexpr double pi=acos(-1.0);
constexpr double eps=1e-9;
template <int m>
struct static_modint
{
using mint=static_modint;
public:
static_modint() : v(0) {}
template <class T>
static_modint(T x)
{
x=(x%(ll)(umod()));
if(x<0)x+=umod();
v=(unsigned int)(x);
}
static_modint(bool x) { v=((unsigned int)(x)%umod()); }
unsigned int val() const { return v; }
mint &operator++()
{
v++;
if(v==umod()) v=0;
return *this;
}
mint &operator--()
{
if(v==0) v=umod();
v--;
return *this;
}
mint operator++(int)
{
mint result=*this;
++*this;
return result;
}
mint operator--(int)
{
mint result=*this;
--*this;
return result;
}
mint &operator+=(const mint &rs)
{
v+=rs.v;
if(v>=umod()) v-=umod();
return *this;
}
mint &operator-=(const mint &rs)
{
if(v<rs.v) v+=umod();
v-=rs.v;
return *this;
}
mint &operator*=(const mint &rs)
{
ull z=v;
z*=rs.v;
v=(unsigned int)(z%umod());
return *this;
}
mint &operator/=(const mint &rs) { return *this=*this*rs.inv(); }
mint operator+() const { return *this; }
mint operator-() const { return mint()-*this; }
mint pow(ll n) const
{
assert(n>=0);
mint x=*this, r=1;
while(n)
{
if(n&1) r*=x;
x*=x;
n>>=1;
}
return r;
}
mint inv() const
{
//assert(v);
return pow(umod()-2);
}
istream &operator>>(istream &in)
{
in>>v;
*this=static_modint(v);
return in;
}
ostream &operator<<(ostream &o)const
{
o<<v;
return o;
}
friend mint operator+(const mint &l, const mint &r)
{
return mint(l)+=r;
}
friend mint operator-(const mint &l, const mint &r)
{
return mint(l)-=r;
}
friend mint operator*(const mint &l, const mint &r)
{
return mint(l)*=r;
}
friend mint operator/(const mint &l, const mint &r)
{
return mint(l)/=r;
}
friend bool operator==(const mint &l, const mint &r)
{
return l.v==r.v;
}
friend bool operator!=(const mint &l, const mint &r)
{
return l.v!=r.v;
}
friend bool operator<(const mint &l, const mint &r)
{
return l.v<r.v;
}
friend bool operator>(const mint &l, const mint &r)
{
return l.v>r.v;
}
friend bool operator<=(const mint &l, const mint &r)
{
return l.v<=r.v;
}
friend bool operator>=(const mint &l, const mint &r)
{
return l.v>=r.v;
}
friend ostream &operator<<(ostream &o, mint u)
{
u.operator<<(o);
return o;
}
friend istream &operator>>(istream &in, mint &u)
{
u.operator>>(in);
return in;
}
private:
unsigned int v;
static constexpr unsigned int umod() { return m; }
};
typedef static_modint<mod> mint;
int val[maxn][6];
void init(const int n=9000)
{
auto f=[](int x)->int
{
string s=to_string(x);
int ans=0;
for(char c:s)
{
ans+=c-'0';
}
return ans;
};
for(int i=1; i<=n; i++)
val[i][0]=i;
for(int i=1; i<=n; i++)
{
for(int k=1; k<=5; k++)
{
val[i][k]=f(val[i][k-1]);
}
}
}
string N;
//bool vis[1005][2][2][9005];
//mint f[1005][2][2][9005];
int timestamp=0;
int vis[1005][9005];
mint f[1005][9005];
const int LIMIT_TAR[]={0, 9000, 35, 11, 9, 9};
set<int>target;
mint dfs(int pos, bool limited, bool leading_zero, int sum, const int tar, int now=0)
{
//if(sum>tar)return 0;
if(sum>*target.rbegin())return 0;
if(pos==0)
{
return target.count(sum);
//return sum==tar;
}
if(!limited&&!leading_zero&&vis[pos][sum]==timestamp)return f[pos][sum];
mint ans=0;
int lim=limited?N[N.size()-pos]-'0':9;
for(int i=0; i<=lim; i++)
{
ans+=dfs(pos-1, limited&&i==lim, leading_zero&&!i, sum+i, tar, now*10+i);
}
if(!limited&&!leading_zero)
{
vis[pos][sum]=timestamp;
return f[pos][sum]=ans;
}
return ans;
}
mint calc(int tar)
{
timestamp++;
return dfs(N.size(), true, true, 0, tar);
}
mint getans(int k, int m)
{
_min(k, 5);
target.clear();
if(k==1)
{
if(m>9000)return 0;
target.insert(m);
return calc(m);
}
mint ans=0;
for(int i=1; i<=9000; i++)
{
if(val[i][k-1]==m)
{
target.insert(i);
//ans+=calc(i);
}
}
ans+=calc(0);
return ans;
}
void test()
{
int maxx=0;
int maxsum=0;
for(int k=2; k<=5; k++)
{
for(int m=1; m<=LIMIT_TAR[k]; m++)
{
int cnt=0;
int sum=0;
for(int i=1; i<=9000; i++)
{
if(val[i][k-1]==m)
{
cnt++;
sum+=i;
}
}
_max(maxx, cnt);
_max(maxsum, sum);
}
}
dbg(maxx, maxsum);
}
int main()//MARK: main
{
#ifndef xxx
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#endif
cout<<fixed<<setprecision(10);
init();
//test();
int t;
cin>>t;
while(t--)
{
int k, m;
cin>>N>>k>>m;
cout<<getans(k, m)<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 40612kb
input:
2 114 1 5 514 2 10
output:
8 10
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 3ms
memory: 40748kb
input:
5 114 1 5 514 2 10 114514 3 7 1919810 2 13 1145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810 1 79
output:
8 10 12724 504 481046284
result:
ok 5 lines
Test #3:
score: -100
Runtime Error
input:
5 3134666912140933323880320519044791121794814671711104987304374190280064994554822259889216567113228716903875026053927191961850586115167336109747673868148288830282192461669674173201533887392623483710043038941036243583011049049915834937139438028987629569618561762595613799223807979488245056374812076511...