QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#314519 | #1193. Ambiguous Encoding | OFforest_1273 | WA | 2ms | 8060kb | C++14 | 2.7kb | 2024-01-25 19:33:08 | 2024-01-25 19:33:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef genshin
#include <experimental/iterator>
#endif
const int INF = 0x3F3F3F3F;
const int maxn = 16;
char s[maxn+1];
int dis[maxn + 1][1 << maxn];
signed main() { ios::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
vector<pair<int, int>> num(n); // len, mask
for(int i=0;i<n;++i){
scanf("%s",s+1);
int x=0,len=0;
for(int j=1;j<=strlen(s+1);++j)x|=(s[j]-'0')<<len,++len;
num[i]={strlen(s+1),x};
}
memset(dis, 0x3f, sizeof dis);
priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq;
for (const auto &[len1, mask1] : num)
for (const auto &[len2, mask2] : num) {
if (len1 == len2 && mask1 == mask2)
continue;
if (len1 < len2)
continue;
if ((mask1 & ((1 << len2) - 1)) != mask2)
continue;
int nxt_mask = mask1 >> len2;
int nxt_len = len1 - len2;
if (dis[nxt_len][nxt_mask] > len1) {
dis[nxt_len][nxt_mask] = len1;
pq.push({len1, nxt_len, nxt_mask});
}
}
// while (!pq.empty()) {
// auto [d, len, mask] = pq.top();
// pq.pop();
// if (d > dis[len][mask])continue;
// for (const auto &[new_len, new_mask] : num) {
// int nxt_mask, nxt_len;
// if (new_len <= len) {
// if ((mask & ((1 << new_len) - 1)) != new_mask)
// continue;
// nxt_mask = mask >> new_len;
// nxt_len = len - new_len;
// }
// else {
// if ((new_mask & ((1 << len) - 1)) != mask)
// continue;
// nxt_mask = new_mask >> len;
// nxt_len = new_len - len;
// }
// int cost = max(0, new_len - len);
// if (dis[nxt_len][nxt_mask] > d + cost) {
// dis[nxt_len][nxt_mask] = d + cost;
// pq.push({d + cost, nxt_len, nxt_mask});
// }
// }
// }
while(!pq.empty()){
auto [d,len,val]=pq.top();pq.pop();
if(d>dis[len][val])continue;
for(int i=0;i<num.size();++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,pq.push({d+cost,nxt_len,nxt_val});
}
}
if (dis[0][0] == INF)
cout << "0\n";
else
cout << dis[0][0] << '\n';
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 8060kb
input:
3 0 01 10
output:
0
result:
wrong answer expected '3', found '0'