QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199044#670. K-th Stringpengpeng_fudanWA 1ms5580kbC++141.3kb2023-10-03 20:36:102023-10-03 20:36:11

Judging History

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

  • [2023-10-03 20:36:11]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5580kb
  • [2023-10-03 20:36:10]
  • 提交

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--;
    }
    //cout<<lw<<' '<<ov<<'\n';
    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&&j>i)  continue;
                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;
            }
        }
    }
    ll zp=1;
    for(int i=1;i<=lw;i++)  zp=zp*i%mod;
    for(int i=1;i<=ov;i++)  zp=zp*i%mod;
    for(int i=0;i<=lw;i++)  ans=(ans+dp[n-sz][i][z-ni-1]*zp%mod)%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: 3688kb

input:

7 12
caedgfb

output:

0

result:

ok single line: '0'

Test #2:

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

input:

2 3
b

output:

1

result:

ok single line: '1'

Test #3:

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

input:

8 4
febadh

output:

0

result:

ok single line: '0'

Test #4:

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

input:

1 1
a

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4 9
bca

output:

0

result:

ok single line: '0'

Test #6:

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

input:

3 2
bc

output:

2

result:

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