QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#361982#7996. 报数 IVhongrock#WA 174ms346832kbC++171.4kb2024-03-23 13:49:372024-03-23 13:49:37

Judging History

你现在查看的是最新测评结果

  • [2024-03-23 13:49:37]
  • 评测
  • 测评结果:WA
  • 用时:174ms
  • 内存:346832kb
  • [2024-03-23 13:49:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int N = 1e3 + 10;
const int M = 1e4 + 10;

int T, n, k, m, dp[N][M], cnt[M], val[M][M];
char s[N];
int a[M];

void add(int &x, int y){
  x += y;
  if(x >= mod)  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<M; ++j){
      for(int k=0; k<10 && j+k<M; ++k){
        add(dp[i][j+k], dp[i-1][j]);
      }
    }
  }
  
  for(int i=1; i<M; ++i){
    val[i][0] = i;
  }

  for(int j=1; j<N; ++j){
    for(int i=1; i<M; ++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<M; ++k){
        if(cur + j + k < M){
          add(cnt[cur + j + k], dp[suf][k]);
        }
      }
    }
    cur += v;
  }
  add(cnt[cur], 1);
  k = min(k, 1000);
  int ret = 0;
  for(int i=1; i<M; ++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: 96ms
memory: 346832kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 116ms
memory: 346668kb

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: 174ms
memory: 344324kb

input:

5
3134666912140933323880320519044791121794814671711104987304374190280064994554822259889216567113228716903875026053927191961850586115167336109747673868148288830282192461669674173201533887392623483710043038941036243583011049049915834937139438028987629569618561762595613799223807979488245056374812076511...

output:

0
36668469
0
443639848
499309433

result:

wrong answer 2nd lines differ - expected: '613343513', found: '36668469'