QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#198452 | #670. K-th String | kjhhjki | WA | 1ms | 3592kb | C++20 | 1.1kb | 2023-10-03 13:59:00 | 2023-10-03 13:59:01 |
Judging History
answer
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define MAXN 100005
#define For(i,a,b) for(int i = (a), endi = (b); i <= endi; ++i)
#define foR(i,a,b) for(int i = (a), endi = (b); i >= endi; --i)
using namespace std;
typedef long long _ll;
const _ll P = 1e9+7;
int n,m,k,len,cnt,sub,dp[27][27][602][2];
_ll ans;
char ch;
string s;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k >> s;
ch = s[0]; m = ch-'a'; len = s.length();
if((k -= len) < 0) { cout << 0; return 0; }
For(i,0,len-1)
if(s[i] < ch)
--m, sub += i, ++cnt;
dp[0][0][0][0] = 1;
For(i,1,n) For(j,0,m) For(k,0,((n+1)*n)>>1)
{
For(t,0,1)
{
dp[i][j][k][t] = (dp[i][j][k][t]+dp[i-1][j][k][t]) %P;
dp[i][j+1][k+n-i][t] = (dp[i][j+1][k+n-i][t]+dp[i-1][j][k][t]) %P;
}
if(i+len-1 <= n)
dp[i+len-1][j][k+(n-i+1)*cnt-sub][1] = (dp[i+len-1][j][k+(n-i+1)*cnt-sub][1]+dp[i-1][j][k][0]);
}
ans=dp[n][m][k][1];
For(i,1,m) ans = ans*i%P;
For(i,1,n-m-len) ans = ans*i%P;
cout << ans;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3488kb
input:
7 12 caedgfb
output:
0
result:
ok single line: '0'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3592kb
input:
2 3 b
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'