QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361883 | #7996. 报数 IV | hongrock# | WA | 11ms | 11780kb | C++17 | 1.6kb | 2024-03-23 13:30:40 | 2024-03-23 13:30:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e3 + 10;
int T, n, k, m, dp[N][N], cnt[N], val[N][N];
char s[N];
int a[N];
void add(int &x, int y){
x += y;
if(x >= mod) x -= mod;
}
void sub(int &x, int y){
x -= y;
if(x < 0) x += mod;
}
int f(int x){
if(x < 10) return x;
if(a[x] != -1) return a[x];
return a[x] = x % 10 + f(x / 10);
}
void init(){
memset(a, -1, sizeof(a));
dp[0][0] = 1;
for(int i=1; i<N; ++i){
for(int j=0; j<N; ++j){
for(int k=0; k<10 && j+k<N; ++k){
add(dp[i][j+k], dp[i-1][j]);
}
}
}
for(int i=1; i<N; ++i){
val[i][0] = i;
}
for(int j=1; j<N; ++j){
for(int i=1; i<N; ++i){
val[i][j] = f(val[i][j-1]);
}
}
}
int solve(){
for(int i=0; i<N; ++i) cnt[i] = 0;
int len = strlen(s);
int cur = 0;
int suf = len;
for(int i=0; i<len; ++i){
int v = s[i] - '0';
--suf;
for(int j=0; j<v; ++j){
for(int k=0; k<N; ++k){
if(cur + j + k < N){
add(cnt[cur + j + k], dp[suf][k]);
}
}
}
cur += v;
}
int lim = 10000;
if(len <= 4){
lim = 0;
for(int i=0; i<len; ++i){
lim = lim * 10 + s[i] - '0';
}
}
add(cnt[cur], 1);
k = min(k, 1000);
int ret = 0;
for(int i=0; i<N; ++i){
if(val[i][k - 1] == m){
add(ret, cnt[i]);
}
}
return ret;
}
int main(){
init();
scanf("%d", &T);
while(T--){
scanf("%s %d %d", s, &k, &m);
printf("%d\n", solve());
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 11760kb
input:
2 114 1 5 514 2 10
output:
8 10
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 11ms
memory: 11764kb
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
Wrong Answer
time: 11ms
memory: 11780kb
input:
5 3134666912140933323880320519044791121794814671711104987304374190280064994554822259889216567113228716903875026053927191961850586115167336109747673868148288830282192461669674173201533887392623483710043038941036243583011049049915834937139438028987629569618561762595613799223807979488245056374812076511...
output:
0 0 0 515859479 892954561
result:
wrong answer 2nd lines differ - expected: '613343513', found: '0'