QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#314796 | #1193. Ambiguous Encoding | cppcppcpp3 | WA | 1ms | 8160kb | C++14 | 1.7kb | 2024-01-26 11:10:26 | 2024-01-26 11:10:26 |
Judging History
answer
// Problem: P6681 [CCO2019] Bad Codes
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P6681
// Memory Limit: 512 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const int M=5e6+5;
const int inf=1e9+7;
bool med;
int n,m,a[N],s,t;
string S[N];
int id(int i,int j){return (i-1)*(m+1)+j+1;}
int cnt,head[M];
struct edge{
int to,w,nxt;
}e[M<<1];
void add(int u,int v,int w){
e[++cnt]={v,w,head[u]},head[u]=cnt;
}
struct node{
int dis,id;
bool operator < (const node &a) const{
return dis>a.dis;
}
};
int f[M];
bool vis[M];
priority_queue<node> q;
void dij(){
for(int i=1;i<=t;++i) f[i]=inf;
f[s]=0,q.push({0,s});
while(!q.empty()){
int u=q.top().id; q.pop();
if(vis[u]) continue;
vis[u]=1;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(f[v]>f[u]+e[i].w){
f[v]=f[u]+e[i].w;
if(!vis[v]) q.push({f[v],v});
}
}
}
}
bool mde;
signed main(){
// cerr << (&med-&mde)/1048576.0 << "MB\n";
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i) cin >> S[i],a[i]=S[i].size();
for(int i=1;i<=n;++i){
for(int j=0;j<a[i];++j){
int dl=a[i]-j;
for(int k=1;k<=n;++k){
if(!j && k==i) continue;
if(a[k]>=dl){
if(S[i].substr(j,dl)==S[k].substr(0,dl)){
add(id(i,dl),id(k,a[k]-dl),a[k]-dl);
}
}else{
if(S[i].substr(j,a[k])==S[k].substr(0,a[k])){
add(id(i,dl),id(i,dl-a[k]),0);
}
}
}
}
}
s=id(n,m)+1,t=s+1;
for(int i=1;i<=n;++i) add(s,id(i,a[i]),a[i]),add(id(i,0),t,0);
dij();
return printf("%d",f[t]==inf ? -1 : f[t]),0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 8160kb
input:
3 0 01 10
output:
0
result:
wrong answer expected '3', found '0'