QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#314098#1193. Ambiguous EncodingyinheeRE 43ms7652kbC++142.1kb2024-01-25 12:42:572024-01-25 12:42:57

Judging History

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

  • [2024-01-25 12:42:57]
  • 评测
  • 测评结果:RE
  • 用时:43ms
  • 内存:7652kb
  • [2024-01-25 12:42:57]
  • 提交

answer

// Problem: P6681 [CCO2019] Bad Codes
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P6681
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// Written by yinhee.

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define mems(x,y) memset(x,y,sizeof x)
#define Mp make_pair
#define eb emplace_back
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define il inline
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a);i>=(b);i--)
#define go(i,u) for(int i=head[u];i;i=e[i].nxt)
	typedef long long ll;
	typedef pair<int,int> pii;
	template<typename T>inline T read(){
		T x=0,f=1;char c=gc();
		while(!isdigit(c)){if(c=='-')f=-1;c=gc();}
		while(isdigit(c))x=x*10+c-48,c=gc();
		return x*f;
	}
}
using namespace my_std;
const int N=1e4+7,M=1e6+7,inf=0x3f3f3f3f,mod=0;
#define ID(i,j) ((i-1)*(m+1)+j+1)
int n,m,dis[N];
string s[N];bool vis[N];
priority_queue<pii> q;
int tot,head[N];
struct node{int to,nxt,cw;}e[M];
il void add(int u,int v,int w){e[++tot]={v,head[u],w},head[u]=tot;}
void Yorushika(){
	scanf("%d",&n),m=16;
	rep(i,1,n)cin>>s[i];
	rep(i,1,n){
		int l=s[i].size();
		rep(j,0,l-1){
			rep(k,1,n){
				int len=l-j;
				if(k==i&&!j)continue;
				if(s[k].size()>=len){
					if(s[i].substr(j,len)==s[k].substr(0,len)){
						int w=s[k].size()-len;
						add(ID(i,len),ID(k,w),w);
					}
				}else{
					// printf("%d %d\n",i,j);
					int sz=s[k].size();
					if(s[i].substr(j,sz)==s[k].substr(0,sz)){
						int w=len-sz;
						add(ID(i,len),ID(i,w),0);
					}
				}
			}
		}
	}
	mems(dis,0x3f);
	rep(i,1,n){
		int u=ID(i,s[i].size());
		dis[u]=s[i].size(),q.push(Mp(-dis[u],u));
	}
	while(q.size()){
		int u=q.top().se;q.pop();
		if(vis[u])continue;
		vis[u]=1;
		go(i,u){
			int v=e[i].to;
			if(dis[v]<=dis[u]+e[i].cw)continue;
			dis[v]=dis[u]+e[i].cw,q.push(Mp(-dis[v],v));
		}
	}
	int ans=inf;
	rep(i,1,n)ans=min(ans,dis[ID(i,0)]);
	printf("%d\n",ans<1e9?ans:0);
}
signed main(){
	int t=1;
	//	scanf("%d",&t);
	while(t--)
		Yorushika();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
0
01
10

output:

3

result:

ok answer is '3'

Test #2:

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

input:

3
00
01
1

output:

0

result:

ok answer is '0'

Test #3:

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

input:

3
00
10
1

output:

0

result:

ok answer is '0'

Test #4:

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

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: 6236kb

input:

3
1101
1
10

output:

4

result:

ok answer is '4'

Test #6:

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

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: 1ms
memory: 4124kb

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: 1ms
memory: 6140kb

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: 4196kb

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: 6220kb

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: 0ms
memory: 4192kb

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: 1ms
memory: 4128kb

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: 4132kb

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: 5ms
memory: 4880kb

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: 6124kb

input:

5
1
01
10101010101
10111000000
10000000101

output:

11

result:

ok answer is '11'

Test #16:

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

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: 6212kb

input:

10
01100
100
00101
0100
1110
11101
1010
01001
000101
10101

output:

12

result:

ok answer is '12'

Test #18:

score: 0
Accepted
time: 43ms
memory: 7652kb

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:

14

result:

ok answer is '14'

Test #19:

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

input:

200
01100101110110
001100111001
1011000110000
101010101010
001000111100010
0010001111110011
010001010101000
010001001001000
1110100000100100
10001011011011
10001000010000
101101001101101
1100010011001001
10010100010100
00001001000111
0100000010011000
111000010100
000101001010000
000100100110101
0010...

output:

145

result:

ok answer is '145'

Test #20:

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

input:

10
1000
00001
01011
001001
110010
11000
110
01010
000001
01100

output:

14

result:

ok answer is '14'

Test #21:

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

input:

10
10111
1100
11011
001
0101
001000
00101
11101
100000
0111

output:

14

result:

ok answer is '14'

Test #22:

score: 0
Accepted
time: 5ms
memory: 4636kb

input:

200
1010111001101110
01010011010100
0111000011011
10000110011100
110110111010100
100001111010001
1110001100001
10001000011101
0001000110011010
1111110000000000
1001000110111001
101011110110111
1101011100010
100001000110
000001011001
011001111111
111101111101000
11101011100010
001011010101000
0001001...

output:

156

result:

ok answer is '156'

Test #23:

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

input:

10
1010
011010
010001
0101
001001
101000
011
111
10010
110

output:

17

result:

ok answer is '17'

Test #24:

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

input:

200
1111100000000
0011100001011100
00000000000111
1100101001111
100100010110111
11001111101011
1100101101101001
100001101010110
01001111000100
001111111001011
011111010101
0011000101010
0110010000000111
110101000110
1110101110011011
1101110010011
0010111101011010
1111010011010
11001000110001
0010010...

output:

188

result:

ok answer is '188'

Test #25:

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

input:

10
000
110100
0111
010
101
11100
010100
00110
011000
010111

output:

18

result:

ok answer is '18'

Test #26:

score: 0
Accepted
time: 7ms
memory: 4884kb

input:

200
1110101101
10111111001
1000011110
1111110011011
01100100101110
010001111000110
1010111010
1000110011010000
11100011110001
11000100001
1011101110011000
000110110000010
111111011000011
0110010000001
10001000101
1101010000
1000000001
1101000010000
01110101110
00000101111
0100111011110
0110110011011...

output:

0

result:

ok answer is '0'

Test #27:

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

input:

200
101010110010
1001001001000111
0010011011011101
1111100000111110
11101010011
10100001001001
000100000000
010011000001011
1100010110010011
11101101110
110001010001
00000111000
011010101001001
10011110110111
0111001111000
110111111010011
1000000110000101
01100101110
00011100011
0111001001111011
101...

output:

0

result:

ok answer is '0'

Test #28:

score: -100
Runtime Error

input:

1000
01000110
11101111
0100011000101111
0010111110011101
1001110111010001
1101000101110010
0111001000110101
0011010110001010
1000101011101011
1110101110111110
1011111001111101
0111110111110100
1111010001111100
0111110001000001
0100000100101010
0010101011010100
1101010001000010
0100001010010011
10010...

output:


result: