QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#345471 | #1193. Ambiguous Encoding | 111445 | WA | 1ms | 3656kb | C++23 | 825b | 2024-03-06 23:51:41 | 2024-03-06 23:51:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int i,j,k,n,m,t;
string s[1005];
map<string,int> f,vis;
priority_queue<pair<int,string> > q;
void fuck(int w,string s1,string s2){
int x=s1.size(),y=s2.size();
if(x<y){
if(s1!=s2.substr(0,x))return;
s2.erase(0,x);
w+=y-x;
}
else{
if(s2!=s1.substr(0,y))return;
s1.erase(0,y);
s2=s1;
}
if(f.count(s2)&&f[s2]<=w)return;
f[s2]=w;
q.push({-w,s2});
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n;
for(i=1;i<=n;i++)cin>>s[i];
for(i=1;i<=n;i++)for(j=i+1;j<=n;j++){
fuck(s[i].size(),s[i],s[j]);
}
while(!q.empty()){
auto [w,s1]=q.top(); q.pop(); w=-w;
if(vis.count(s1))continue;
vis[s1]=1;
for(i=1;i<=n;i++){
fuck(w,s1,s[i]);
}
}
if(!f[""])f[""]=-1;
cout<<f[""];
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3656kb
input:
3 0 01 10
output:
3
result:
ok answer is '3'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
input:
3 00 01 1
output:
-1
result:
wrong answer expected '0', found '-1'