QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#345471#1193. Ambiguous Encoding111445WA 1ms3656kbC++23825b2024-03-06 23:51:412024-03-06 23:51:41

Judging History

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

  • [2024-03-06 23:51:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3656kb
  • [2024-03-06 23:51:41]
  • 提交

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[""];
}

Details

Tip: Click on the bar to expand more detailed information

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'