QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#314145#1193. Ambiguous EncodingyhdddRE 8ms5476kbC++142.0kb2024-01-25 13:27:122024-01-25 13:27:14

Judging History

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

  • [2024-01-25 13:27:14]
  • 评测
  • 测评结果:RE
  • 用时:8ms
  • 内存:5476kb
  • [2024-01-25 13:27:12]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define mems(x,y) memset(x,y,sizeof x)
using namespace std;
const int maxn=20010;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,m;
string s[maxn];
int head[maxn],tot;
struct nd{
	int nxt,to,w;
}e[maxn<<1];
void add(int u,int v,int w){e[++tot]={head[u],v,w};head[u]=tot;}
int dis[maxn];
struct Dis{
	int dis,id;
	bool operator<(const Dis&tmp)const{return dis>tmp.dis;}
};
bool vis[maxn];
priority_queue<Dis> q;
int id(int u,int v){return (u-1)*(m+1)+v+1;}
const int inf=1e9;
void work(){
	n=read();m=16;
	for(int i=1;i<=n;i++)cin>>s[i];
	for(int i=1;i<=n;i++){
		for(int j=0;j<s[i].size();j++){
			for(int k=1;k<=n;k++){
				if(i==k&&!j)continue;
				if(s[k].size()>=s[i].size()-j){
					if(s[i].substr(j,s[i].size()-j)==s[k].substr(0,s[i].size()-j)){
						int res=s[k].size()-(s[i].size()-j);
						add(id(i,s[i].size()-j),id(k,res),res);
					}
				}
				else{
					if(s[i].substr(j,s[k].size())==s[k]){
						int res=s[i].size()-j-s[k].size();
						add(id(i,s[i].size()-j),id(i,res),0);
					}
				}
			}
		}
	}
	mems(dis,0x3f);
	for(int i=1;i<=n;i++){
		dis[id(i,s[i].size())]=s[i].size();
		q.push({s[i].size(),id(i,s[i].size())});
	}
	while(!q.empty()){
		int u=q.top().id;q.pop();
		if(vis[u])continue;vis[u]=1;
		// cout<<u<<" "<<dis[u]<<"\n";
		for(int i=head[u];i;i=e[i].nxt){
			int v=e[i].to;
			if(dis[v]>dis[u]+e[i].w){
				dis[v]=dis[u]+e[i].w;
				q.push({dis[v],v});
			}
		}
	}
	int ans=inf;
	for(int i=1;i<=n;i++)ans=min(ans,dis[id(i,0)]);
	if(ans==inf)ans=0;
	printf("%lld\n",ans);
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=1;
	while(T--)work();
}

詳細信息

Test #1:

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

input:

3
0
01
10

output:

3

result:

ok answer is '3'

Test #2:

score: 0
Accepted
time: 1ms
memory: 4760kb

input:

3
00
01
1

output:

0

result:

ok answer is '0'

Test #3:

score: 0
Accepted
time: 1ms
memory: 4568kb

input:

3
00
10
1

output:

0

result:

ok answer is '0'

Test #4:

score: 0
Accepted
time: 1ms
memory: 4568kb

input:

10
1001
1011
01000
00011
01011
1010
00100
10011
11110
0110

output:

13

result:

ok answer is '13'

Test #5:

score: 0
Accepted
time: 1ms
memory: 4564kb

input:

3
1101
1
10

output:

4

result:

ok answer is '4'

Test #6:

score: 0
Accepted
time: 2ms
memory: 5040kb

input:

100
1010011110001
00000100010101
011010100100001
11100001100011
10010001010
1110001110110011
01001100111
1010100110010100
00000100111010
100111001100101
0010000000010
0111110011100110
0100111000001
1100101111110001
1100100110001
10100011010
10100000011000
1111001111001110
000000000101011
10101111011...

output:

102

result:

ok answer is '102'

Test #7:

score: 0
Accepted
time: 0ms
memory: 4584kb

input:

10
0110
001100
0100
0001
100
001010
0010
100010
1100
11101

output:

10

result:

ok answer is '10'

Test #8:

score: 0
Accepted
time: 0ms
memory: 4600kb

input:

10
1001
10111
11011
00010
001
001100
110
01110
111101
11100

output:

10

result:

ok answer is '10'

Test #9:

score: 0
Accepted
time: 1ms
memory: 4520kb

input:

10
0001
0101
1001
101
0010
010
00000
1000
00001
111101

output:

10

result:

ok answer is '10'

Test #10:

score: 0
Accepted
time: 0ms
memory: 5112kb

input:

100
0100001001101111
00001000100011
001111100110101
1010001010001
01110010101011
1110101100011
00100000100110
01111110100
110001111010
10101010001
00010000100100
00010011100
01101001100010
010111010101
00101110101001
00110100110110
00111001101
0001110011000011
11101100110
101111001011001
00101110100...

output:

110

result:

ok answer is '110'

Test #11:

score: 0
Accepted
time: 3ms
memory: 4840kb

input:

100
010110000010110
111001111001
00000010100111
1011000100011100
1010110100001000
0101110010110
11101010001
0001101001001101
10011111110010
01010001101
11011101010
011011111011001
111000111110
01011100011
0000111110110
000110001011
110100011000
10010011011
0011001010001
1010001110000110
100100100001...

output:

113

result:

ok answer is '113'

Test #12:

score: 0
Accepted
time: 0ms
memory: 4596kb

input:

10
011
011000
111011
0101
101000
010100
1101
10100
11111
001001

output:

11

result:

ok answer is '11'

Test #13:

score: 0
Accepted
time: 1ms
memory: 4500kb

input:

10
101
110
00000
100011
010
110001
001001
1110
011111
01001

output:

11

result:

ok answer is '11'

Test #14:

score: 0
Accepted
time: 8ms
memory: 5476kb

input:

200
100101110111000
0111100000111
1010110010001110
000001000000
111000100101
111010000110100
11100110010100
100110111110
1000100110110
0100010010111
001100010101
100001001110100
1110000011001111
0110100100100
111111111110
1110111010110
1101101000111
0001101001110001
000010110111110
101100110010
1010...

output:

116

result:

ok answer is '116'

Test #15:

score: 0
Accepted
time: 1ms
memory: 4760kb

input:

5
1
01
10101010101
10111000000
10000000101

output:

11

result:

ok answer is '11'

Test #16:

score: 0
Accepted
time: 0ms
memory: 4812kb

input:

100
000010101110
10101111011110
10000000001
001101011110101
110001010100
11110111011
0101101111010001
101010001101011
100001110100
100010110011000
1000001001101001
0011100110101
011110111100010
0100101100010
10001101011
011110010101011
0011001001000
0100001010100
11110110011
011101001011
01101011011...

output:

118

result:

ok answer is '118'

Test #17:

score: 0
Accepted
time: 1ms
memory: 4792kb

input:

10
01100
100
00101
0100
1110
11101
1010
01001
000101
10101

output:

12

result:

ok answer is '12'

Test #18:

score: -100
Runtime Error

input:

500
0110100111
10110100011100
100011111010111
010010111
0011100001101
10011001101101
0110010011
0101100
1000010111011
01110010110
111001111000
0110100010101
011001100100101
001000110001100
110100000101
100101100101111
0101111111110
00101001000010
1101100
0110000000
00011100000
1110010101
00000100010...

output:


result: