Submission #990824

# Submission time Handle Problem Language Result Execution time Memory
990824 2024-05-31T12:43:07 Z Pacybwoah Spy 3 (JOI24_spy3) C++17
100 / 100
83 ms 6596 KB
#include "Aoi.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
namespace {
    vector<vector<pair<pair<int, ll>, int>>> graph;
    int n, m, q, k;
}
std::string aoi(int N, int M, int Q, int K, std::vector<int> A, std::vector<int> B, std::vector<long long> C, std::vector<int> T, std::vector<int> X) {
    n = N, m = M, q = Q, k = K;
    graph.resize(n);
    for(int i = 0; i < m; i++){
        graph[A[i]].emplace_back(make_pair(B[i], C[i]), i);
        graph[B[i]].emplace_back(make_pair(A[i], C[i]), i);
    }
    priority_queue<pair<ll, pair<int, int>>, vector<pair<ll, pair<int, int>>>, greater<pair<ll, pair<int, int>>>> pq;
    vector<ll> dist(n, 1e18);
    dist[0] = 0;
    vector<pair<int, int>> par(n);
    pq.emplace(0, make_pair(0, 0));
    while(!pq.empty()){
        auto [d, tmp] = pq.top();
        auto [node, eidd] = tmp;
        pq.pop();
        if(dist[node] < d) continue;
        if(node != 0){
            par[node] = make_pair((A[eidd] == node ? B[eidd] : A[eidd]), eidd);
        }
        for(auto &[x, eid]: graph[node]){
            if(dist[x.first] > d + x.second){
                dist[x.first] = d + x.second;
                pq.emplace(dist[x.first], make_pair(x.first, eid));
            }
        }
    }
    vector<bool> isq(n), isk(m);
    for(auto x: T) isq[x] = 1;
    for(auto x: X) isk[x] = 1;
    vector<int> qtag(n, -1), ktag(m, -1);
    int now;
    for(int i = q - 1; i >= 0; i--){
        now = T[i];
        while(now != 0){
            auto &[p, eid] = par[now];
            if(isk[eid]) ktag[eid] = i;
            now = p;
        }
    }
    for(int i = 0; i < q; i++){
        now = T[i];
        while(now != 0){
            auto &[p, eid] = par[now];
            if(isk[eid]){
                if(ktag[eid] < i && ktag[eid] != -1){
                    qtag[i] = eid;
                    break;
                }
            }
            now = p;
        }
    }
    vector<int> kpos(m);
    for(int i = 0; i < k; i++) kpos[X[i]] = i;
    string ans;
    for(int s = 0; s < k; s += 6){
        int e = min(s + 5, k - 1);
        ll enc = 0, base = 1;
        for(int i = s; i <= e; i++){
            enc += base * (ktag[X[i]] + 1);
            base *= 17;
        }
        for(int i = 0; i < 25; i++){
            if(enc & (1 << i)){
                ans += '1';
            }
            else ans += '0';
        }
    }
    for(int i = 1; i < q; i++){
        int enc;
        if(qtag[i] == -1) enc = 0;
        else enc = kpos[qtag[i]] + 1;
        for(int j = 0; j < 9; j++){
            if(enc & (1 << j)){
                ans += '1';
            }
            else ans += '0';
        }
    }
    return ans;
}

// g++ -std=gnu++20 -O2 -o grader joisc24_d1C_grader.cpp joisc24_d1C_Aoi.cpp joisc24_d1C_Bitaro.cpp
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<string>
#include "Bitaro.h"
using namespace std;
typedef long long ll;
namespace {
}

void bitaro(int N, int M, int Q, int K, std::vector<int> A, std::vector<int> B, std::vector<long long> C, std::vector<int> T, std::vector<int> X, std::string s) {
    int n = N, m = M, q = Q, k = K;
    vector<int> ktag(k), qtag(q);
    int snow = 0;
    //cout << s << "\n";
    for(int st = 0; st < k; st += 6){
        int e = min(k, st + 6);
        int enc = 0;
        for(int i = snow; i < snow + 25; i++){
            if(s[i] == '1') enc += (1 << (i - snow));
        }
        snow += 25;
        for(int i = st; i < e; i++){
            ktag[i] = enc % 17 - 1;
            enc /= 17;
            //cout << i << " " << ktag[i] << "\n";
        }
    }
    for(int i = 1; i < q; i++){
        for(int j = snow; j < snow + 9; j++){
            if(s[j] == '1') qtag[i] += (1 << (j - snow));
        }
        snow += 9;
        qtag[i]--;
        //cout << i << " " << qtag[i] << "\n";
    }
    //for(auto x: qtag) cout << x << " ";
    //cout << "\n";
    //for(auto x: ktag) cout << x << " ";
    //cout << "\n";
    vector<bool> used(k), isk(m), isq(n);
    vector<int> kpos(m);
    for(int i = 0; i < k; i++) isk[X[i]] = 1;
    for(int i = 0; i < q; i++) isq[T[i]] = 1;
    for(int i = 0; i < k; i++) kpos[X[i]] = i;
    vector<vector<pair<pair<int, ll>, int>>> graph;
    auto set_graph = [&](){
        vector<vector<pair<pair<int, ll>, int>>>().swap(graph);
        graph.resize(n);
        for(int i = 0; i < m; i++){
            if(!isk[i]){
                graph[A[i]].emplace_back(make_pair(B[i], C[i]), i);
                graph[B[i]].emplace_back(make_pair(A[i], C[i]), i);
            }
        }
        for(int i = 0; i < k; i++){
            if(used[i]){
                graph[A[X[i]]].emplace_back(make_pair(B[X[i]], 1), X[i]);
                graph[B[X[i]]].emplace_back(make_pair(A[X[i]], 1), X[i]);
            }
        }
    };
    vector<int> head(k, -1);
    auto dijk = [&](int nowq){
        priority_queue<pair<ll, pair<int, int>>, vector<pair<ll, pair<int, int>>>, greater<pair<ll, pair<int, int>>>> pq;
        vector<ll> dist(n, 1e18);
        dist[0] = 0;
        pq.emplace(0, make_pair(0, 0));
        vector<pair<int, int>> par(n);
        while(!pq.empty()){
            auto [d, tmp] = pq.top();
            auto [node, eidd] = tmp;
            pq.pop();
            if(dist[node] < d) continue;
            if(node != 0){
                par[node] = make_pair((A[eidd] == node ? B[eidd] : A[eidd]), eidd);
            }
            for(auto &[x, eid]: graph[node]){
                if(dist[x.first] > d + x.second){
                    dist[x.first] = d + x.second;
                    pq.emplace(dist[x.first], make_pair(x.first, eid));
                }
            }
        }
        vector<int> ans;
        int lst = -1;
        while(nowq != 0){
            auto &[p, eid] = par[nowq];
            if(isk[eid]){
                if(lst != -1){
                    head[lst] = kpos[eid];
                }
                lst = kpos[eid];
            }
            nowq = p;
            ans.push_back(eid);
        }
        reverse(ans.begin(), ans.end());
        //for(auto x: ans) cout << x << "\n";
        //cout << "\n";
        answer(ans);
    };
    for(int i = 0; i < q; i++){
        fill(used.begin(), used.end(), 0);
        for(int j = 0; j < k; j++){
            if(ktag[j] == i) used[j] = 1;
        }
        if(i != 0){
            while(qtag[i] >= 0){
                used[qtag[i]] = 1;
                qtag[i] = head[qtag[i]];
            }
        }
        set_graph();
        dijk(T[i]);
    }
}
// g++ -std=gnu++20 -O2 -o grader joisc24_d1C_grader.cpp joisc24_d1C_Aoi.cpp joisc24_d1C_Bitaro.cpp
# Verdict Execution time Memory Grader output
1 Correct 22 ms 5012 KB Output is correct
2 Correct 0 ms 776 KB Output is correct
3 Correct 58 ms 6056 KB Output is correct
4 Correct 51 ms 5700 KB Output is correct
5 Correct 63 ms 5836 KB Output is correct
6 Correct 64 ms 5836 KB Output is correct
7 Correct 60 ms 5676 KB Output is correct
8 Correct 55 ms 5648 KB Output is correct
9 Correct 48 ms 5756 KB Output is correct
10 Correct 21 ms 5576 KB Output is correct
11 Correct 60 ms 5776 KB Output is correct
12 Correct 61 ms 5728 KB Output is correct
13 Correct 65 ms 5640 KB Output is correct
14 Correct 71 ms 5784 KB Output is correct
15 Correct 55 ms 5616 KB Output is correct
16 Correct 14 ms 5240 KB Output is correct
17 Correct 59 ms 5252 KB Output is correct
18 Correct 57 ms 5420 KB Output is correct
19 Correct 61 ms 6332 KB Output is correct
20 Correct 46 ms 6376 KB Output is correct
21 Correct 59 ms 6480 KB Output is correct
22 Correct 73 ms 6268 KB Output is correct
23 Correct 51 ms 6292 KB Output is correct
24 Correct 74 ms 6304 KB Output is correct
25 Correct 69 ms 5960 KB Output is correct
26 Correct 66 ms 5712 KB Output is correct
27 Correct 0 ms 776 KB Output is correct
28 Correct 56 ms 6040 KB Output is correct
29 Correct 33 ms 4112 KB Output is correct
30 Correct 69 ms 6284 KB Output is correct
31 Correct 34 ms 6088 KB Output is correct
32 Correct 69 ms 6256 KB Output is correct
33 Correct 71 ms 5860 KB Output is correct
34 Correct 63 ms 6400 KB Output is correct
35 Correct 60 ms 6348 KB Output is correct
36 Correct 57 ms 6332 KB Output is correct
37 Correct 16 ms 3444 KB Output is correct
38 Correct 34 ms 4304 KB Output is correct
39 Correct 33 ms 4260 KB Output is correct
40 Correct 8 ms 3836 KB Output is correct
41 Correct 83 ms 6472 KB Output is correct
42 Correct 43 ms 6328 KB Output is correct
43 Correct 79 ms 6576 KB Output is correct
44 Correct 19 ms 6592 KB Output is correct
45 Correct 17 ms 3408 KB Output is correct
46 Correct 28 ms 4084 KB Output is correct
47 Correct 30 ms 3984 KB Output is correct
48 Correct 0 ms 1028 KB Output is correct
49 Correct 0 ms 784 KB Output is correct
50 Correct 13 ms 5004 KB Output is correct
51 Correct 2 ms 1032 KB Output is correct
52 Correct 0 ms 776 KB Output is correct
53 Correct 21 ms 5332 KB Output is correct
54 Correct 15 ms 3852 KB Output is correct
55 Correct 40 ms 4472 KB Output is correct
56 Correct 38 ms 6360 KB Output is correct
57 Correct 59 ms 6444 KB Output is correct
58 Correct 54 ms 4892 KB Output is correct
59 Correct 79 ms 6480 KB Output is correct
60 Correct 64 ms 6324 KB Output is correct
61 Correct 73 ms 6368 KB Output is correct
62 Correct 69 ms 6048 KB Output is correct
63 Correct 76 ms 6440 KB Output is correct
64 Correct 14 ms 5396 KB Output is correct
65 Correct 37 ms 4256 KB Output is correct
66 Correct 30 ms 6596 KB Output is correct
67 Correct 36 ms 4240 KB Output is correct
68 Correct 33 ms 6288 KB Output is correct
69 Correct 0 ms 776 KB Output is correct
70 Correct 0 ms 776 KB Output is correct
71 Correct 0 ms 784 KB Output is correct
72 Correct 17 ms 3160 KB Output is correct
73 Correct 37 ms 3852 KB Output is correct
74 Correct 38 ms 3784 KB Output is correct
75 Correct 12 ms 4096 KB Output is correct
76 Correct 0 ms 776 KB Output is correct
77 Correct 57 ms 6240 KB Output is correct
78 Correct 49 ms 6116 KB Output is correct
79 Correct 56 ms 6156 KB Output is correct
80 Correct 0 ms 776 KB Output is correct
81 Correct 65 ms 5684 KB Output is correct
82 Correct 60 ms 5832 KB Output is correct
83 Correct 66 ms 5828 KB Output is correct