답안 #259334

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259334 2020-08-07T15:41:06 Z keko37 Two Transportations (JOI19_transportations) C++14
0 / 100
7 ms 2056 KB
#include<bits/stdc++.h>
#include "Azer.h"

using namespace std;

typedef pair <int, int> pi;

const int MAXN = 2005;

int n, m, mx, ans, ex, tip, mn, ind, ost;
vector <pi> v[MAXN];
int bio[MAXN], dist[MAXN];

//void SendA (bool x) {}

void SendNum (int val, int br) {
    for (int i = br - 1; i >= 0; i--) {
        SendA((bool) (val & (1 << i)));
    }
}

void update (int x, int d) {
    bio[x] = 1; dist[x] = d;
    mx = max(mx, dist[x]);
    for (auto par : v[x]) {
        int sus = par.first, w = par.second;
        if (bio[sus] == 0 && dist[x] + w < dist[sus]) dist[sus] = dist[x] + w;
    }
}

void solve () {
    if (ost == 0) return;
    if (tip == 0) {
        mn = 501, ind = -1;
        for (int j = 1; j <= n; j++) {
            if (bio[j] == 0 && dist[j] - mx < mn) {
                mn = dist[j] - mx;
                ind = j;
            }
        }

        SendNum(mn, 9);
        ans = 0; ex = 1;
    } else if (tip == 1) {
        if (ans == 0) {
            SendNum(ind, 11);
            tip = 4;
            solve();
        } else {
            ans = 0; ex = 9;
        }
    } else if (tip == 2) {
        mn = ans;
        ans = 0; ex = 11;
    } else if (tip == 3) {
        ind = ans;
        tip = 4;
        solve();
    } else if (tip == 4) {
        update(ind, mx + mn);
        tip = 0;
        solve();
    }
}

void ReceiveA (bool x) {
    ans *= 2;
    if (x) ans++;
    ex--;
    if (ex == 0) {
        tip++;
        solve();
    }
}

std::vector<int> Answer () {
    vector <int> res(n);
    for (int i = 0; i < n; i++) res[i] = dist[i];
    return res;
}

void InitA (int N, int A, std::vector <int> U, std::vector <int> V, std::vector <int> C) {
    n = N; m = A;
    for (int i = 0; i < m; i++) {
        v[U[i]].push_back({V[i], C[i]});
        v[V[i]].push_back({U[i], C[i]});
    }
    for (int i = 1; i <= n; i++) dist[i] = 1e9;
    update(0, 0);
    ost = n-1;
    solve();
}

/*int main () {
    return 0;
}*/
#include<bits/stdc++.h>
#include "Baijan.h"

using namespace std;

typedef pair <int, int> pi;

const int MAXN = 2005;

int n, m, mx, ans, ex, tip, mn, ind, ost;
vector <pi> v[MAXN];
int bio[MAXN], dist[MAXN];

//void SendB (bool x) {}

void SendNum (int val, int br) {
    for (int i = br - 1; i >= 0; i--) {
        SendB((bool) (val & (1 << i)));
    }
}

void update (int x, int d) {
    bio[x] = 1; dist[x] = d;
    mx = max(mx, dist[x]);
    for (auto par : v[x]) {
        int sus = par.first, w = par.second;
        if (bio[sus] == 0 && dist[x] + w < dist[sus]) dist[sus] = dist[x] + w;
    }
}

void solve () {
    if (ost == 0) return;
    if (tip == 0) {
        mn = 501, ind = -1;
        for (int j = 1; j <= n; j++) {
            if (bio[j] == 0 && dist[j] - mx < mn) {
                mn = dist[j] - mx;
                ind = j;
            }
        }

        ans = 0; ex = 9;
    } else if (tip == 1) {
        if (mn < ans) {
            SendNum(1, 1);
            SendNum(mn, 9);
            SendNum(ind, 11);
        } else {
            SendNum(0, 1);
            ans = 0; ex = 11;
            tip = 3;
            solve();
        }
    } else if (tip == 2) {
        ind = ans;
        tip = 3;
        solve();
    } else if (tip == 3) {
        update(ind, mx + mn);
        tip = 0;
        solve();
    }
}

void ReceiveB (bool x) {
    ans *= 2;
    if (x) ans++;
    ex--;
    if (ex == 0) {
        tip++;
        solve();
    }
}

void InitB (int N, int B, std::vector <int> U, std::vector <int> V, std::vector <int> C) {
    n = N; m = B;
    for (int i = 0; i < m; i++) {
        v[U[i]].push_back({V[i], C[i]});
        v[V[i]].push_back({U[i], C[i]});
    }
    for (int i = 1; i <= n; i++) dist[i] = 1e9;
    update(0, 0);
    ost = n-1;
    solve();
}

/*int main () {
    return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1280 KB Output is correct
2 Incorrect 6 ms 2056 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1840 KB Output isn't correct
2 Halted 0 ms 0 KB -