QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#314777 | #1193. Ambiguous Encoding | dieselhuang | WA | 2ms | 9388kb | C++14 | 1.3kb | 2024-01-26 10:57:43 | 2024-01-26 10:57:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define mems(x, y) memset(x, y, sizeof(x))
int n, m = 0, dis[65540][17];
bool bk[65540][17];
char c[1010];
struct Node{
int x, len;
bool operator <(const Node u) const{ return dis[x][len] > dis[u.x][len]; }
}a[1010];
Node mrg(Node u, Node v){
if(u.len > v.len) return mrg(v, u);
if(u.x != (v.x & (1 << u.len) - 1)) return {-1, 0};
return {v.x >> u.len, v.len - u.len};
}
priority_queue <Node> q;
int main()
{
int i, j;
Node u, v;
scanf("%d", &n);
mems(c, '\0'); mems(dis, 0x3f3f3f3f); mems(bk, false);
for(i = 1; i <= n; i++){
scanf("%s", c);
for(j = 0, a[i].x = 0; c[j] >> 1 == 24; j++){
if(c[j] ^ '0') a[i].x |= 1 << j;
c[j] = '\0';
}
a[i].len = j;
}
for(i = 1; i <= n; i++){
for(j = i + 1; j <= n; j++){
if(i != j){
u = mrg(a[i], a[j]);
if(u.x >= 0){ dis[u.x][u.len] = min(a[i].len, a[j].len); q.push(u); }
}
}
}
while(q.size() > 0){
u = q.top(); q.pop();
if(u.len == 0){ printf("%d", dis[u.x][u.len]); return 0; }
if(bk[u.x][u.len]) continue;
bk[u.x][u.len] = true;
for(i = 1; i <= n; i++){
v = mrg(u, a[i]);
if(v.x >= 0){ dis[v.x][v.len] = min(dis[v.x][v.len], dis[u.x][u.len] + min(a[i].len, u.len)); q.push(v); }
}
}
printf("0");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9252kb
input:
3 0 01 10
output:
3
result:
ok answer is '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 9252kb
input:
3 00 01 1
output:
0
result:
ok answer is '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 9272kb
input:
3 00 10 1
output:
0
result:
ok answer is '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 9324kb
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: 2ms
memory: 9232kb
input:
3 1101 1 10
output:
4
result:
ok answer is '4'
Test #6:
score: 0
Accepted
time: 1ms
memory: 9232kb
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: 0ms
memory: 9388kb
input:
10 0110 001100 0100 0001 100 001010 0010 100010 1100 11101
output:
10
result:
ok answer is '10'
Test #8:
score: 0
Accepted
time: 1ms
memory: 9312kb
input:
10 1001 10111 11011 00010 001 001100 110 01110 111101 11100
output:
10
result:
ok answer is '10'
Test #9:
score: -100
Wrong Answer
time: 1ms
memory: 9304kb
input:
10 0001 0101 1001 101 0010 010 00000 1000 00001 111101
output:
11
result:
wrong answer expected '10', found '11'