QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#318148 | #1193. Ambiguous Encoding | c20230201 | WA | 1ms | 4368kb | C++14 | 1.5kb | 2024-01-30 16:26:00 | 2024-01-30 16:26:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=2e4, inf=1e18;
unordered_map<ll,ll> lg;
ll v[1005], id[1005][17], dis[maxn], vis[maxn];
string s[1005];
vector<pair<ll,ll> > g[maxn];
ll lowbit(ll x) {
return x&(-x);
}
struct node {
ll x;
ll v;
bool operator < (const node&other) const{
return v>other.v;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
ll n,tot=0; cin>>n;
for(ll i=1;i<=16;i++) lg[1<<i]=i;
for(ll i=1;i<=n;i++) {
cin>>s[i];
for(ll j=0;j<s[i].size();j++) v[i]+=((s[i][j]-'0')<<j);
for(ll j=0;j<=s[i].size();j++) id[i][j]=++tot;
}
for(ll i=1;i<=n;i++) {
for(ll j=0;j<s[i].size();j++) {
ll len=s[i].size()-j;
ll val=(v[i]>>j);
for(ll k=1;k<=n;k++) {
if(k==i) continue;
ll x=min(min(lg[lowbit(val^v[k])==0?(1<<16):lowbit(val^v[k])],len),(ll)s[k].size());
if(x<len&&x<s[k].size()) continue;
else if(x<len) g[id[i][j]].push_back({id[i][j+x],x});
else g[id[i][j]].push_back({id[k][x],x});
}
}
}
priority_queue<node> q;
for(ll i=1;i<=tot;i++) dis[i]=inf;
for(ll i=1;i<=n;i++) dis[id[i][0]]=0, q.push((node){id[i][0],0});
while(q.size()) {
ll x=q.top().x; q.pop();
if(vis[x]) continue;
vis[x]=1;
for(auto p:g[x]) {
ll y=p.first, w=p.second;
if(dis[y]>dis[x]+w) dis[y]=dis[x]+w, q.push((node){y,dis[y]});
}
}
ll ans=inf;
for(ll i=1;i<=n;i++) ans=min(ans,dis[id[i][s[i].size()]]);
if(ans!=inf) cout<<ans<<'\n';
else cout<<"0\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4072kb
input:
3 0 01 10
output:
3
result:
ok answer is '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4108kb
input:
3 00 01 1
output:
0
result:
ok answer is '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 4132kb
input:
3 00 10 1
output:
0
result:
ok answer is '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 4088kb
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: 4368kb
input:
3 1101 1 10
output:
4
result:
ok answer is '4'
Test #6:
score: 0
Accepted
time: 1ms
memory: 4324kb
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: 4068kb
input:
10 0110 001100 0100 0001 100 001010 0010 100010 1100 11101
output:
10
result:
ok answer is '10'
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 4368kb
input:
10 1001 10111 11011 00010 001 001100 110 01110 111101 11100
output:
11
result:
wrong answer expected '10', found '11'