Submission #266559

#TimeUsernameProblemLanguageResultExecution timeMemory
266559dolphingarlicTwo Transportations (JOI19_transportations)C++14
52 / 100
2134 ms102680 KiB
#include "Azer.h"

#include <bits/stdc++.h>
using namespace std;

namespace {
int N, stage = 0, cnt;
vector<pair<int, int>> graph[2000];
vector<int> shortest;
priority_queue<pair<int, int>> pq;
bool visited[2000];
pair<int, int> candidate = {0, 0};

void reset() {
    visited[candidate.second] = true;
    shortest[candidate.second] = candidate.first;
    for (pair<int, int> i : graph[candidate.second])
        pq.push({-candidate.first - i.second, i.first});
    N--;

    if (!N) return;

    while (pq.size() && visited[pq.top().second]) pq.pop();
    if (pq.size()) candidate = {-pq.top().first, pq.top().second};
    else candidate = {INT_MAX, -1};

    for (int i = 0; i < 20; i++) SendA((candidate.first & (1 << i)) >> i);
    cnt = stage = 0;
}
}  // namespace

void InitA(int N, int A, vector<int> U, vector<int> V, vector<int> C) {
    ::N = N;
    shortest.resize(N);
    for (int i = 0; i < A; i++) {
        graph[U[i]].push_back({V[i], C[i]});
        graph[V[i]].push_back({U[i], C[i]});
    }
    reset();
}

void ReceiveA(bool x) {
    if (stage == 0) {
        if (x) {
            stage++;
            candidate = {0, 0};
        } else {
            for (int i = 0; i < 11; i++) SendA((candidate.second & (1 << i)) >> i);
            reset();
        }
    } else if (stage == 1) {
        candidate.first |= x << cnt++;
        if (cnt == 20) {
            stage++;
            cnt = 0;
        }
    } else {
        candidate.second |= x << cnt++;
        if (cnt == 11) reset();
    }
}

vector<int> Answer() {
    return shortest;
}
#include "Baijan.h"

#include <bits/stdc++.h>
using namespace std;

namespace {
int N, stage = 0, cnt, a_shortest;
vector<pair<int, int>> graph[2000];
vector<int> shortest;
priority_queue<pair<int, int>> pq;
bool visited[2000];
pair<int, int> candidate = {0, 0};

void reset() {
    visited[candidate.second] = true;
    shortest[candidate.second] = candidate.first;
    for (pair<int, int> i : graph[candidate.second])
        pq.push({-candidate.first - i.second, i.first});

    while (pq.size() && visited[pq.top().second]) pq.pop();
    if (pq.size()) candidate = {-pq.top().first, pq.top().second};
    else candidate = {INT_MAX, -1};

    cnt = stage = a_shortest = 0;
}
}  // namespace

void InitB(int N, int B, vector<int> S, vector<int> T, vector<int> D) {
    ::N = N;
    shortest.resize(N);
    for (int i = 0; i < B; i++) {
        graph[S[i]].push_back({T[i], D[i]});
        graph[T[i]].push_back({S[i], D[i]});
    }
    reset();
}

void ReceiveB(bool y) {
    if (stage == 0) {
        a_shortest |= y << cnt++;
        if (cnt == 20) {
            if (a_shortest > candidate.first) {
                SendB(1);
                for (int i = 0; i < 20; i++) SendB((candidate.first & (1 << i)) >> i);
                for (int i = 0; i < 11; i++) SendB((candidate.second & (1 << i)) >> i);
                reset();
            } else {
                SendB(0);
                cnt = 0;
                candidate = {a_shortest, 0};
                stage++;
            }
        }
    } else if (stage == 1) {
        candidate.second |= y << cnt++;
        if (cnt == 11) reset();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...