QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#198997 | #670. K-th String | pengpeng_fudan | WA | 1ms | 5488kb | C++14 | 1.0kb | 2023-10-03 20:10:35 | 2023-10-03 20:10:36 |
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];
ll d[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';
for(int i=2;i<=sz;i++){
if(s[i]<s[1]){
ni+=n-(x+i-1)+1;
lw--;
}
}
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;k++){
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])%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: 100
Accepted
time: 1ms
memory: 5488kb
input:
7 12 caedgfb
output:
0
result:
ok single line: '0'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 5468kb
input:
2 3 b
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'