QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#304023#1193. Ambiguous EncodingNYCU_CartesianTree#WA 2ms4192kbC++142.9kb2024-01-13 12:13:142024-01-13 12:13:14

Judging History

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

  • [2024-01-13 12:13:14]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4192kb
  • [2024-01-13 12:13:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int const N = 1005;
string a[N];
int len[N];
vector<pair < pair<int, int>, int> > graph[N][16];
int dest[N][16];
int dis[N][16];
bool vis[N][16];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        len[i] = a[i].size();
        for(int j = 0; j < len[i]; j++){
            dis[i][j] = 1e9;
        }
    }
    dis[n][0] = 1e9;
    for(int i = 0; i < n; i++){
        for(int k = 0; k < len[i]; k++){
            for(int j = 0; j < n; j++){
                if(i == j)
                    continue;
                bool can_add = 1;
                for(int t = 0; t < min(len[i] - k, len[j]); t++){
                    if(a[i][k + t] != a[j][t]){
                        can_add = 0;
                        break;
                    }
                }
                if(can_add){
                    if(len[i] - k < len[j]){
                        graph[i][k].push_back({{j, (len[i] - k)}, len[i] - k});
                    }else if(len[i] - k == len[j]){
                        dest[i][k] = len[j];
                        break;
                    }else{
                        graph[i][k].push_back({{i, k + len[j]}, len[j]});
                    }
                }
            }
        }
    }
    // for(int i = 0; i < n; i++){
    //     for(int k = 0; k < len[i]; k++){
    //         for(auto &j : graph[i][k]){
    //             cerr << i << ' ' << k << ' ' << j.first.first << ' ' << j.first.second << ' ' << j.second << '\n';
    //         }
    //     }
    // }
    priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >, greater<pair<int, pair<int, int> > > > pq;
    for(int i = 0; i < n; i++){
        pq.push({0, {i, 0}});
        dis[i][0] = 0;
    }
    while(!pq.empty()){
        auto top = pq.top();
        pq.pop();
        if(top.second.first == n){
            break;
        }
        if(vis[top.second.first][top.second.second]){
            continue;
        }
        vis[top.second.first][top.second.second] = 1;
        if(dest[top.second.first][top.second.second]){
            if(dis[n][0] > top.first + dest[top.second.first][top.second.second]){
                dis[n][0] = top.first + dest[top.second.first][top.second.second];
                pq.push({dis[n][0], {n, 0}});
            }
            continue;
        }
        for(auto &i : graph[top.second.first][top.second.second]){
            if(dis[i.first.first][i.first.second] > top.first + i.second){
                dis[i.first.first][i.first.second] = top.first + i.second;
                pq.push({dis[i.first.first][i.first.second], i.first});
            }
        }
    }
    if(dis[n][0] == 1e9){
        cout << 0 << '\n';
    }else{
        cout << dis[n][0] << '\n';
    }
}

詳細信息

Test #1:

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

input:

3
0
01
10

output:

3

result:

ok answer is '3'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3948kb

input:

3
00
01
1

output:

0

result:

ok answer is '0'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3932kb

input:

3
00
10
1

output:

0

result:

ok answer is '0'

Test #4:

score: 0
Accepted
time: 1ms
memory: 4000kb

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

input:

3
1101
1
10

output:

4

result:

ok answer is '4'

Test #6:

score: 0
Accepted
time: 2ms
memory: 4192kb

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

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

input:

10
1001
10111
11011
00010
001
001100
110
01110
111101
11100

output:

11

result:

wrong answer expected '10', found '11'