Submission #996260

# Submission time Handle Problem Language Result Execution time Memory
996260 2024-06-10T10:18:02 Z 79brue Two Transportations (JOI19_transportations) C++17
0 / 100
15 ms 788 KB
#include "Azer.h"
#include <bits/stdc++.h>

using namespace std;
const int INF = 2e9;

namespace {
    int n, cnt;
    vector<pair<int, int> > link[2002];
    int dist[2002];
    bool visited[2002];

    int recent_dist;
    int curr_node, curr_dist;
    int opp_node, opp_dist, opp_qidx, mode;

    void update(int x){
        visited[x] = 1;
        for(auto [y, z]: link[x]){
            dist[y] = min(dist[y], dist[x] + z);
        }
        recent_dist = dist[x];
    }

    void send_info(){
        curr_node = -1, curr_dist = INF;
        for(int i=0; i<n; i++) if(!visited[i] && curr_dist > dist[i]){
            curr_node = i;
            curr_dist = dist[i];
        }

        int diff = curr_dist - recent_dist;
        assert(0 <= diff && diff < 512);
        for(int i=0; i<9; i++) SendA((diff >> i) & 1);

        opp_node = opp_qidx = mode = 0, opp_dist = recent_dist;
    }
}

void InitA(int N, int A, vector<int> U, vector<int> V, vector<int> C) {
    n = N;
    for(int i=0; i<A; i++){
        link[U[i]].push_back(make_pair(V[i], C[i]));
        link[V[i]].push_back(make_pair(U[i], C[i]));
    }

    for(int i=1; i<n; i++) dist[i] = INF;
    update(0);

    cnt = 1;
    send_info();
}

void ReceiveA(bool x) {
    if(!mode){
        opp_dist += (int(x) << opp_qidx++);
        if(opp_qidx == 9){ /// 정보가 모두 전달되었다
            opp_qidx = 0;
            if(curr_dist <= opp_dist){ /// 내가 정보를 보내고 업데이트
                update(curr_node);
                for(int i=0; i<11; i++) SendA((curr_node >> i) & 1);

                if(++cnt == n) return;
                else send_info();
            }
            else mode = 1;
        }
    }
    else{
        opp_node += (int(x) << opp_qidx++);
        if(opp_qidx == 11){
            dist[opp_node] = opp_dist;
            update(opp_node);

            if(++cnt == n) return;
            else send_info();
            mode = 0;
        }
    }
}

vector<int> Answer(){
    return vector<int> (dist, dist+n);
}
#include "Baijan.h"
#include <bits/stdc++.h>

using namespace std;
const int INF = 2e9;

namespace{
    int n, cnt;
    vector<pair<int, int> > link[2002];
    int dist[2002];
    bool visited[2002];

    int recent_dist;
    int curr_node, curr_dist;
    int opp_node, opp_dist, opp_qidx, mode;

    void update(int x){
        visited[x] = 1;
        for(auto [y, z]: link[x]){
            dist[y] = min(dist[y], dist[x] + z);
        }
        recent_dist = dist[x];
    }

    void send_info(){
        curr_node = -1, curr_dist = INF;
        for(int i=0; i<n; i++) if(!visited[i] && curr_dist > dist[i]){
            curr_node = i;
            curr_dist = dist[i];
        }

        int diff = curr_dist - recent_dist;
        assert(0 <= diff && diff < 512);
        for(int i=0; i<9; i++) SendB((diff >> i) & 1);

        opp_node = opp_qidx = mode = 0, opp_dist = recent_dist;
    }
}

void InitB(int N, int B, vector<int> S, vector<int> T, vector<int> D) {
    n = N;
    for(int i=0; i<B; i++){
        link[S[i]].push_back(make_pair(T[i], D[i]));
        link[T[i]].push_back(make_pair(S[i], D[i]));
    }

    for(int i=1; i<n; i++) dist[i] = INF;
    update(0);

    cnt = 1;
    send_info();
}

void ReceiveB(bool x) {
    if(!mode){
        opp_dist += (int(x) << opp_qidx++);
        if(opp_qidx == 9){ /// 정보가 모두 전달되었다
            opp_qidx = 0;
            if(curr_dist <= opp_dist){ /// 내가 정보를 보내고 업데이트
                update(curr_node);
                for(int i=0; i<11; i++) SendB((curr_node >> i) & 1);

                if(++cnt == n) return;
                else send_info();
            }
            else mode = 1;
        }
    }
    else{
        opp_node += (int(x) << opp_qidx++);
        if(opp_qidx == 11){
            dist[opp_node] = opp_dist;
            update(opp_node);

            if(++cnt == n) return;
            else send_info();
            mode = 0;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 788 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -