QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#248986#1193. Ambiguous EncodingJeffreyWA 1ms3876kbC++142.1kb2023-11-11 23:22:342023-11-11 23:22:34

Judging History

你现在查看的是最新测评结果

  • [2023-11-11 23:22:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3876kb
  • [2023-11-11 23:22:34]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    int n, d[1003][17] = {}, l[1003] = {}, z = mod;
    bool b[1003][17] = {};
    string s[1003] = {};
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> s[i], l[i] = (int)s[i].length();
    for (int i = 1; i <= n; i++) for (int j = 0; j <= 16; j++) d[i][j] = mod;
    priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> q;
    for (int i = 1; i <= n; i++) for (int j = 1; j < i; j++) {
        if (l[i] > l[j]) {
            if (s[i].substr(0, l[j]) == s[j]) {
                d[i][l[i] - l[j]] = l[i];
                q.push({l[j], {i, l[i] - l[j]}});
            }
        } else {
            if (s[j].substr(0, l[i]) == s[i]) {
                d[j][l[j] - l[i]] = l[j];
                q.push({l[i], {j, l[j] - l[i]}});
            }
        }
    }
    while (!q.empty()) {
        int x = q.top().second.first, y = q.top().second.second;
        q.pop();
        if (b[x][y]) continue; b[x][y] = 1;
        for (int i = 1; i <= n; i++) {
            if (l[i] <= y) {
                if (s[i] == s[x].substr(l[x] - l[i], l[i])) {
                    if (d[x][y - l[i]] > d[x][y]) {
                        d[x][y - l[i]] = d[x][y];
                        q.push({d[x][y - l[i]], {x, y - l[i]}});
                    }
                }
            } else {
                if (s[i].substr(0, y) == s[x].substr(l[x] - y, y)) {
                    if (d[i][l[i] - y] > d[x][y] + l[i] - y) {
                        d[i][l[i] - y] = d[x][y] + l[i] - y;
                        q.push({d[i][l[i] - y], {i, l[i] - y}});
                    }
                }
            }
        }
    }
    //for (int i = 1; i <= n; i++) for (int j = 0; j <= 5; j++) cout << d[i][j] << " \n"[j == 5];
    for (int i = 1; i <= n; i++) z = min(z, d[i][0]);
    if (z == mod) z = 0;
    cout << z << '\n';
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3720kb

input:

3
0
01
10

output:

3

result:

ok answer is '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3720kb

input:

3
00
01
1

output:

0

result:

ok answer is '0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3856kb

input:

3
00
10
1

output:

0

result:

ok answer is '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3716kb

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: 3656kb

input:

3
1101
1
10

output:

4

result:

ok answer is '4'

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3876kb

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'