QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#314529 | #1193. Ambiguous Encoding | OFforest_1273 | WA | 2ms | 12696kb | C++14 | 1.5kb | 2024-01-25 19:46:23 | 2024-01-25 19:46:23 |
Judging History
answer
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define PII pair<int,int>
using namespace std;
inline int read(){int s=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+(c^48),c=getchar();return s*f;}
const int N=17;
int n,dis[N][1<<N];
PII num[N];
priority_queue<tuple<int,int,int>,vector<tuple<int,int,int> >,greater<tuple<int,int,int> > > Q;
int main(){
n=read(),memset(dis,0x3f,sizeof(dis));
for(int i=1;i<=n;++i){
string s;cin>>s;
int x=0,len=0;
for(char c:s)x|=(c&1)<<len,++len;
num[i]={s.size(),x};
}
for(int i=1;i<=n;++i)/*初始化*/
for(int j=1;j<=n;++j){
int len1=num[i].first,len2=num[j].first,val1=num[i].second,val2=num[j].second;
if((len1==len2&&val1==val2)||len1<len2)continue;
if((val1&((1<<len2)-1))!=val2)continue;
int nxt_len=len1-len2,nxt_val=val1>>len2;
if(dis[nxt_len][nxt_val]>len1)dis[nxt_len][nxt_val]=len1,Q.push({len1,nxt_len,nxt_val});
}
while(!Q.empty()){
auto [d,len,val]=Q.top();Q.pop();
if(d>dis[len][val])continue;
for(int i=1;i<=n;++i){
int len2=num[i].first,val2=num[i].second,nxt_len,nxt_val,flag=0;
if(len>=len2&&((val&((1<<len2)-1))==val2))nxt_len=len-len2,nxt_val=val>>len2,flag=1;
else if(len<len2&&(val2&((1<<len)-1))==val)nxt_len=len2-len,nxt_val=val2>>len,flag=1;
if(!flag)continue;
int cost=max(0,len2-len);
if(d+cost<dis[nxt_len][nxt_val])dis[nxt_len][nxt_val]=d+cost,Q.push({d+cost,nxt_len,nxt_val});
}
}
printf("%d\n",dis[0][0]==inf?0:dis[0][0]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 12668kb
input:
3 0 01 10
output:
3
result:
ok answer is '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 12412kb
input:
3 00 01 1
output:
0
result:
ok answer is '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 12524kb
input:
3 00 10 1
output:
0
result:
ok answer is '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 12440kb
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: 0ms
memory: 12340kb
input:
3 1101 1 10
output:
4
result:
ok answer is '4'
Test #6:
score: -100
Wrong Answer
time: 2ms
memory: 12696kb
input:
100 1010011110001 00000100010101 011010100100001 11100001100011 10010001010 1110001110110011 01001100111 1010100110010100 00000100111010 100111001100101 0010000000010 0111110011100110 0100111000001 1100101111110001 1100100110001 10100011010 10100000011000 1111001111001110 000000000101011 10101111011...
output:
11
result:
wrong answer expected '102', found '11'