QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#234664 | #3169. Editing Explosion | PhantomThreshold# | AC ✓ | 84ms | 7452kb | C++20 | 1.7kb | 2023-11-01 20:36:58 | 2023-11-01 20:36:58 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
//#define int long long
using namespace std;
const int mod = 998244353;
const int maxn = 12;
const int mask = 60005;
inline void add(int &a,const int &b){ a+=b; if(a>=mod)a-=mod; }
int n,D;
int a[maxn],pw[12];
int f[22][mask];
void dpnh(int h[],int c,int nh[])
{
nh[0]=h[0]+1;
for(int i=1;i<=n;i++)
{
nh[i]= min( min( nh[i-1]+1,h[i]+1 ),h[i-1]+(a[i]!=c) );
}
}
void geth(int L,int s,int h[])
{
h[0]=L;
for(int i=1;i<=n;i++)
{
int c= s/pw[i-1]%3;
if(c==1) c=-1;
else if(c==2) c=1;
h[i]=h[i-1]+c;
}
}
int getcode(int h[])
{
int s=0;
for(int i=1;i<=n;i++)
{
int c=h[i]-h[i-1];
if(c==-1) s+= pw[i-1];
else if(c==1) s+=pw[i-1]*2;
}
return s;
}
int h[maxn],nh[maxn];
//vector< pair<int,int> >cand;
//int use[50];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
pw[0]=1; for(int i=1;i<maxn;i++) pw[i]=pw[i-1]*3;
string str; cin>>str;
n=str.size(); str=' '+str;
for(int i=1;i<=n;i++) a[i]=str[i]-'A'+1;
cin>>D;
/*
0 : 0
1 : -1
2 : 1
*/
/*
for(int i=1;i<=n;i++) if(!use[a[i]])
{
cand.emplace_back(a[i],1);
use[a[i]]=1;
}
{
int num=0,las=0;
for(int i=1;i<=26;i++) if(!use[i])
{
num++; las=i;
}
cand.emplace_back(
}*/
int S=0;
for(int i=1;i<=n;i++) S+=2*pw[i-1];
f[0][S]=1;
int ans=0;
int mxS=pw[n];
for(int L=0;L<=n+D;L++)
{
for(int s=0;s<mxS;s++) if(f[L][s])
{
geth(L,s,h);
if(h[n]==D) add(ans,f[L][s]);
if(L<n+D)
{
for(int c=1;c<=26;c++)
{
dpnh(h,c,nh);
int ns=getcode(nh);
add(f[L+1][ns],f[L][s]);
}
}
}
}
cout<<ans<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3412kb
input:
ICPC 1
output:
230
result:
ok single line: '230'
Test #2:
score: 0
Accepted
time: 57ms
memory: 7356kb
input:
PROGRAMMER 10
output:
110123966
result:
ok single line: '110123966'
Test #3:
score: 0
Accepted
time: 84ms
memory: 7452kb
input:
ABCDEFGHIJ 10
output:
258519532
result:
ok single line: '258519532'
Test #4:
score: 0
Accepted
time: 6ms
memory: 6148kb
input:
AAAAABBBBB 10
output:
877770338
result:
ok single line: '877770338'
Test #5:
score: 0
Accepted
time: 3ms
memory: 3716kb
input:
NOWISTHE 0
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 4ms
memory: 3652kb
input:
NOWISTHE 1
output:
434
result:
ok single line: '434'
Test #7:
score: 0
Accepted
time: 0ms
memory: 4704kb
input:
ABABABABAB 10
output:
555168781
result:
ok single line: '555168781'
Test #8:
score: 0
Accepted
time: 39ms
memory: 5916kb
input:
ABCDDEFGHI 3
output:
21580956
result:
ok single line: '21580956'
Test #9:
score: 0
Accepted
time: 71ms
memory: 6988kb
input:
ABCDDEFGHI 8
output:
49338700
result:
ok single line: '49338700'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
A 10
output:
864056661
result:
ok single line: '864056661'