QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#350321#1193. Ambiguous Encodingzjy0001WA 0ms4356kbC++141.4kb2024-03-10 17:14:592024-03-10 17:15:00

Judging History

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

  • [2024-03-10 17:15:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4356kb
  • [2024-03-10 17:14:59]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=1e3+5,M=2e4+5,INF=1e9+7;
int n,cnt,D[M];
string s[N];
vector<int>id[N];
map<string,bool>mp;
vector<pair<int,int>>G[M];
priority_queue<pair<int,int>>Q;
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>s[i],mp[s[i]]=1,id[i].resize(s[i].length());
        for(int j=0;j<s[i].length();++j)id[i][j]=cnt++;
    }
    for(int i=1;i<=n;++i)for(int j=1;j<s[i].length();++j)
        for(int k=1;k<=n;++k){
            int l=min(j,(int)s[k].length());
            if(s[k].substr(0,l)==s[i].substr(s[i].length()-j,l))
                if(l==s[k].length())G[id[i][j]].emplace_back(id[i][j-l],l);
                else G[id[i][j]].emplace_back(id[k][s[k].length()-j],l);
        }
    fill(D,D+cnt,INF);
    for(int i=1;i<=n;++i)
        for(int j=1;j<s[i].length();++j)
            if(mp.count(s[i].substr(0,j)))
                D[id[i][s[i].length()-j]]=j,
                Q.emplace(-j,id[i][s[i].length()-j]);
    while(!Q.empty()){
        const auto [d,u]=Q.top();Q.pop();
        if(-d!=D[u])continue;
        for(auto [v,w]:G[u])if(D[v]>D[u]+w)D[v]=D[u]+w,Q.emplace(-D[v],v);
    }
    int ans=INF;
    for(int i=1;i<=n;++i)ans=min(ans,D[id[i][0]]);
    cout<<(ans>=INF?-1:ans)<<'\n';
    return 0;
}
/*

*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 4284kb

input:

3
0
01
10

output:

3

result:

ok answer is '3'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 4356kb

input:

3
00
01
1

output:

-1

result:

wrong answer expected '0', found '-1'