QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199025#670. K-th Stringpengpeng_fudanWA 1ms5768kbC++141.1kb2023-10-03 20:24:002023-10-03 20:24:00

Judging History

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

  • [2023-10-03 20:24:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5768kb
  • [2023-10-03 20:24:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
using ll=long long;
const ll mod=1e9+7;
int n,z;
string s;
int sz;
ll ans=0;
ll dp[30][30][1010];
void solve(int x) {
    for(int i=0;i<=n;i++)   for(int j=0;j<=sz;j++)  for(int k=0;k<=z;k++)   dp[i][j][k]=0;
    int ni=sz-1;
    int lw=s[1]-'a';
    int ov=n-(s[1]-'a'+1);
    for(int i=2;i<=sz;i++){
        if(s[i]<s[1]){
            ni+=n-(x+i-1)+1;
            lw--;
        }
        else ov--;
    }
    if(ni>=z)   return ;
    dp[0][0][0]=1;
    for(int i=1;i<=n-sz;i++){
        for(int j=0;j<=lw;j++){
            for(int k=0;k<=z-ni-1;k++){
                if(i-j<=ov) dp[i][j][k]=dp[i-1][j][k];
                int ad=(i<x?n-i+1:n-(i+sz)+1);
                if(j>=1&&k>=ad)    dp[i][j][k]=(dp[i][j][k]+dp[i-1][j-1][k-ad])%mod;
            }
        }
    }
    for(int i=0;i<=lw;i++)  ans=(ans+dp[n-sz][i][z-ni-1])%mod;
}
int main() {
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n>>z>>s;
    s=' '+s;
    sz=s.size()-1;
    for(int i=1;i<=n-sz+1;i++)  solve(i);
    cout<<ans<<'\n';
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5744kb

input:

7 12
caedgfb

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3520kb

input:

2 3
b

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5604kb

input:

8 4
febadh

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3428kb

input:

1 1
a

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

4 9
bca

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3512kb

input:

3 2
bc

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

1 1
a

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 1ms
memory: 5768kb

input:

8 8
acgefbdh

output:

1

result:

ok single line: '1'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3520kb

input:

4 7
cb

output:

2

result:

ok single line: '2'

Test #10:

score: -100
Wrong Answer
time: 1ms
memory: 5544kb

input:

8 36
hgfaec

output:

1

result:

wrong answer 1st lines differ - expected: '2', found: '1'