QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#199020 | #670. K-th String | pengpeng_fudan | WA | 1ms | 5552kb | C++14 | 1.1kb | 2023-10-03 20:16:59 | 2023-10-03 20:17:00 |
Judging History
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--;
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5552kb
input:
7 12 caedgfb
output:
692091874
result:
wrong answer 1st lines differ - expected: '0', found: '692091874'