QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#318272#1193. Ambiguous EncodingwullaaaWA 1ms5936kbC++141.4kb2024-01-30 21:43:542024-01-30 21:43:54

Judging History

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

  • [2024-01-30 21:43:54]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5936kb
  • [2024-01-30 21:43:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5,INF=1e9,M=16e6+5;
int n,len[N],a[N],cnt,dis[M],id[N][15],ed;
char s[20];
struct node{
    int i,j,val;
    bool operator< (const node &other)const{
        return val>other.val;
    }
};
priority_queue<node> q;
bool vis[M];
int main(){
    scanf("%d",&n),ed=cnt=1;
    for(int i=1;i<=n;++i){
        scanf("%s",s+1),len[i]=strlen(s+1);
        for(int j=0;j<len[i];++j) id[i][j]=++cnt;
        id[i][len[i]]=ed;
        for(int j=1;j<=len[i];++j) a[i]=a[i]<<1|(s[j]-'0');
    }
    for(int i=1;i<=cnt;++i) dis[i]=INF;
    for(int i=1;i<=n;++i) q.push({i,0,dis[id[i][0]]=len[i]});
    while(!q.empty()){
        int i=q.top().i,j=q.top().j,x=id[i][j]; q.pop();
        if(vis[x]) continue; vis[x]=true;
        for(int k=1;k<=n;++k) if((i^k)||j){
            if(len[k]<=len[i]-j){
                if(a[k]==((a[i]>>(len[i]-j-len[k]))&((1<<len[k])-1))&&dis[id[i][j+len[k]]]>dis[x])
                    dis[id[i][j+len[k]]]=dis[x],q.push({i,j+len[k],dis[x]+len[k]});
            }else{
                if((a[i]&((1<<len[i]-j)-1))==(a[k]>>len[k]-len[i]+j)&&dis[id[k][len[i]-j]]>dis[x]+len[k]-len[i]+j)
                    dis[id[k][len[i]-j]]=dis[x]+len[k]-len[i]+j,q.push({k,len[i]-j,dis[id[k][len[i]-j]]});
            }
        }
    }
    if(vis[ed]) printf("%d",dis[ed]);
    else puts("0");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
0
01
10

output:

3

result:

ok answer is '3'

Test #2:

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

input:

3
00
01
1

output:

0

result:

ok answer is '0'

Test #3:

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

input:

3
00
10
1

output:

0

result:

ok answer is '0'

Test #4:

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

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

input:

3
1101
1
10

output:

4

result:

ok answer is '4'

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 5872kb

input:

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

output:

0

result:

wrong answer expected '102', found '0'