QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#56589 | #3169. Editing Explosion | tricyzhkx | AC ✓ | 633ms | 54240kb | C++14 | 1.2kb | 2022-10-20 13:55:30 | 2022-10-20 13:55:31 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
typedef vector<int> State;
int n,d,tot,f[1000010],du[1000010],trans[1000010][26];
State st[1000010];
queue<int> que;
map<State,int> mp;
char s[20];
void upd(int &a,int b){(a+=b)>=mod?a-=mod:0;}
void dfs(int u)
{
State S=st[u];
for(int c=0;c<26;c++)
{
State T(n+1);
for(int i=0;i<=n;i++) T[i]=S[i]+1;
for(int i=1;i<=n;i++) T[i]=min(T[i],S[i-1]+(s[i]!=c+'A'));
for(int i=1;i<=n;i++) T[i]=min(T[i],T[i-1]+1);
bool ok=0;
for(int i=0;i<=n;i++) ok|=(T[i]<=d);
if(!ok) continue;
if(mp.count(T)) trans[u][c]=mp[T];
else st[++tot]=T,trans[u][c]=mp[T]=tot,dfs(tot);
}
}
int main()
{
int ans=0;
scanf("%s%d",s+1,&d);n=strlen(s+1);
State S(n+1);
for(int i=1;i<=n;i++) S[i]=i;
tot=mp[S]=1;st[1]=S;dfs(1);
f[1]=1;
for(int i=1;i<=tot;i++)
for(int j=0;j<26;j++)
if(trans[i][j]) du[trans[i][j]]++;
que.push(1);
while(!que.empty())
{
int u=que.front(),v;que.pop();
for(int i=0;i<26;i++)
if((v=trans[u][i])>0)
{
upd(f[v],f[u]);
if(!(--du[v])) que.push(v);
}
}
for(int i=1;i<=tot;i++)
if(st[i][n]==d) upd(ans,f[i]);
cout<<ans<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 27124kb
input:
ICPC 1
output:
230
result:
ok single line: '230'
Test #2:
score: 0
Accepted
time: 373ms
memory: 43832kb
input:
PROGRAMMER 10
output:
110123966
result:
ok single line: '110123966'
Test #3:
score: 0
Accepted
time: 633ms
memory: 54240kb
input:
ABCDEFGHIJ 10
output:
258519532
result:
ok single line: '258519532'
Test #4:
score: 0
Accepted
time: 26ms
memory: 28276kb
input:
AAAAABBBBB 10
output:
877770338
result:
ok single line: '877770338'
Test #5:
score: 0
Accepted
time: 2ms
memory: 27208kb
input:
NOWISTHE 0
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 11ms
memory: 27236kb
input:
NOWISTHE 1
output:
434
result:
ok single line: '434'
Test #7:
score: 0
Accepted
time: 5ms
memory: 27576kb
input:
ABABABABAB 10
output:
555168781
result:
ok single line: '555168781'
Test #8:
score: 0
Accepted
time: 26ms
memory: 28712kb
input:
ABCDDEFGHI 3
output:
21580956
result:
ok single line: '21580956'
Test #9:
score: 0
Accepted
time: 394ms
memory: 45024kb
input:
ABCDDEFGHI 8
output:
49338700
result:
ok single line: '49338700'
Test #10:
score: 0
Accepted
time: 11ms
memory: 27080kb
input:
A 10
output:
864056661
result:
ok single line: '864056661'