QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#314193 | #1193. Ambiguous Encoding | kkio | WA | 2ms | 3888kb | C++20 | 1.9kb | 2024-01-25 14:07:58 | 2024-01-25 14:07:59 |
Judging History
answer
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <utility>
using namespace std;
#define fir first
#define sec second
#define lson(i) (tr[i].ls)
#define rson(i) (tr[i].rs)
#define FIO(file) freopen(file".in","r",stdin), freopen(file".out","w",stdout)
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef __int128_t i128;
typedef __uint128_t u128;
const int maxn=1005;
char s[maxn][20];
int n,len[maxn];
int rid[maxn][20],id;
vector< pair<int,int> > G[maxn*20];
int dis[maxn*20];
bool vis[maxn];
priority_queue< pair<int,int> > q;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%s",s[i]+1);
len[i]=strlen(s[i]+1);
}
for(int i=1;i<=n;i++)
for(int j=0;j<=len[i];j++)
rid[i][j]=++id;
//for(int i=1;i<=n;i++)cout<<len[i]<<' ';cout<<'\n';
for(int i=1;i<=n;i++)
{
for(int j=len[i];j>=1;j--)
{
for(int k=1;k<=n;k++)
if(j==len[i]&&k==i)continue;
else
{
int t=min(j,len[k]);
bool flag=1;
for(int z=1;z<=t;z++)
if(s[i][len[i]-j+z]!=s[k][z]){flag=0;break;}
if(!flag)continue;
//cout<<"!"<<i<<' '<<j<<' '<<k<<'\n';
if(j<len[k])G[rid[i][j]].push_back({rid[k][len[k]-j],t});
else G[rid[i][j]].push_back({rid[i][j-len[k]],t});
}
}
}
memset(dis,0x3f,sizeof dis);
for(int i=1;i<=n;i++)
dis[rid[i][len[i]]]=0,q.push({0,rid[i][len[i]]});
while(!q.empty())
{
int u=q.top().second;
q.pop();
if(vis[u])continue;
vis[u]=1;
for(auto [v,w]:G[u])
if(dis[v]>dis[u]+w)
{
dis[v]=dis[u]+w;
q.push({-dis[v],v});
}
}
int ans=1e9;
for(int i=1;i<=n;i++)
ans=min(ans,dis[rid[i][0]]);
if(ans>=1e9)puts("0");
else cout<<ans<<'\n';
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3704kb
input:
3 0 01 10
output:
3
result:
ok answer is '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
3 00 01 1
output:
0
result:
ok answer is '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
3 00 10 1
output:
0
result:
ok answer is '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3752kb
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: 3880kb
input:
3 1101 1 10
output:
4
result:
ok answer is '4'
Test #6:
score: -100
Wrong Answer
time: 2ms
memory: 3888kb
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'