QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#190273#6635. Strange Keyboarducup-team870WA 284ms204972kbC++171.7kb2023-09-28 16:23:372023-09-28 16:23:39

Judging History

你现在查看的是最新测评结果

  • [2023-09-28 16:23:39]
  • 评测
  • 测评结果:WA
  • 用时:284ms
  • 内存:204972kb
  • [2023-09-28 16:23:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define ll long long
#define vi vector<int>
#define db double
const ll mod=1231453023109121,INF=1e18;
const int N=5005,bs=131,M=1e6+6;
void Min(ll &x,ll y){x=min(x,y);}
unordered_map<ll,vi>mp;
char s[M];
ll l[N]; ll dis[N],dp[N][N],ans[N];
void slv(){
    int n,k;cin>>n>>k;
    mp.clear();
    rep(i,0,k)l[i]=INF;
    rep(i,1,n){
        cin>>s+1;
        int len=strlen(s+1); ll v=0;
        rep(j,1,len){
            v=(bs*v+s[j])%mod; mp[v].push_back(len-j);
        }
        Min(l[len%k],k+len);
    }
    dis[0]=0; rep(i,1,k-1)dis[i]=INF;
    vi vis(k+1);
    while(1){
        ll mi=INF; int x;
        rep(i,0,k-1){
            if(!vis[i] && dis[i]<mi){
                mi=dis[i]; x=i;
            }
        }
        if(mi==INF)break; vis[x]=1;
        rep(i,0,k-1)Min(dis[i],dis[x]+l[(i-x+k)%k]);
    }
    cin>>s+1; int m=strlen(s+1); //下次用n吧..
    rep(l,1,m){
        ll v=0;
        rep(r,l,m){
            dp[l][r]=INF;
            v=(v*bs+s[r]);
            if(!mp.count(v))continue;
            for(auto len:mp[v]){
                int x=((-len)%k+k)%k;
                if(dis[x]<INF)Min(dp[l][r],(dis[x]+len)/k+1);
            }
        }
    }
    rep(i,1,m){
        ans[i]=dp[1][i];
        rep(j,1,i-1)Min(ans[i], ans[j]+dp[j+1][i]);
    }
    // cout<<dp[1][3]<<' '<<dp[4][5]<<endl;
    cout<<(ans[m]>=INF?-1:ans[m])<<'\n';
}
signed main(){
    IOS
    int T;cin>>T;
    while(T--)slv();
}
/*
1
2 3
defgh
abc
abcde
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3508kb

input:

2
2 3
defgh
abc
abcde
1 1
a
b

output:

3
-1

result:

ok 2 number(s): "3 -1"

Test #2:

score: -100
Wrong Answer
time: 284ms
memory: 204972kb

input:

1
1413 4867
yumnkkghwtqnhpmmsbfwypcwudihegsvtdaykueuqozagpgdnhbwzoqrqswyctzonwmjdjmmpyzbyihhpyznmqltcuckqmcybbdafoexqztxhzlfjowznisnxtgoiqjztogldyegajmegalqgawrzotuntocmsagvkzdnwhmaewuxiuhvintpzwyrkgapnmegpveyuuorrfvrfakjyetfaoqtvwghlslsvmahrkvzkwpaviufknrpuapicqdnn
yumnkkghwtqnhpmmsbfwypcwudihegsvt...

output:

-1

result:

wrong answer 1st numbers differ - expected: '10', found: '-1'