Submission #113255

# Submission time Handle Problem Language Result Execution time Memory
113255 2019-05-24T12:59:35 Z imeimi2000 Two Transportations (JOI19_transportations) C++17
100 / 100
2028 ms 85216 KB
#include "Azer.h"
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>
#include <iostream>
#define fs first
#define se second

using namespace std;
typedef pair<int, int> pii;

namespace {

const int inf = 1e9;
const int non = 505;
int n;
vector<pii> edge[2000];
int dist[2000];
queue<int> r;
priority_queue<pii> q;
int mode, mx, nd, nx;
int sync[2000];

}  // namespace

static int get(int bit) {
    int ret = 0;
    for (int i = 0; i < bit; ++i) {
        if (r.front()) ret |= 1 << i;
        r.pop();
    }
    return ret;
}

static void send(int x, int bit) {
    while (bit--) {
        SendA(x & 1);
        x >>= 1;
    }
}

static void sendNext() {
    nd = non + mx;
    while (!q.empty()) {
        int d, x;
        tie(d, x) = q.top();
        d = -d;
        if (dist[x] != d) {
            q.pop();
            continue;
        }
        if (sync[x]) {
            q.pop();
            for (pii i : edge[x]) {
                if (sync[i.fs]) continue;
                if (dist[i.fs] <= dist[x] + i.se) continue;
                dist[i.fs] = dist[x] + i.se;
                q.emplace(-dist[i.fs], i.fs);
            }
            continue;
        }
        nd = d;
        nx = x;
        break;
    }
    nd -= mx;
    send(nd, 9);
}

void InitA(int N, int A, std::vector<int> U, std::vector<int> V,
           std::vector<int> C) {
    n = N;
    for (int i = 0; i < A; ++i) {
        edge[U[i]].emplace_back(V[i], C[i]);
        edge[V[i]].emplace_back(U[i], C[i]);
    }
    for (int i = 1; i < n; ++i) dist[i] = inf;
    q.emplace(0, 0);
    sync[0] = 1;
    sendNext();
}

static void pro1() {
    int bd = get(9);
    if (nd == non && bd == non) return;
    if (nd < bd) {
        sync[nx] = 1;
        mx = dist[nx];
        send(nx, 11);
        sendNext();
    }
    else {
        mode = 1;
        mx += bd;
    }
}

static void pro2() {
    int bx = get(11);
    dist[bx] = mx;
    sync[bx] = 1;
    q.emplace(-dist[bx], bx);
    sendNext();
    mode = 0;
}

void ReceiveA(bool x) {
    r.push(x);
    if (mode == 0 && r.size() == 9) pro1();
    else if (mode == 1 && r.size() == 11) pro2();
}

vector<int> Answer() {
    vector<int> ans;
    for (int i = 0; i < n; ++i) ans.push_back(dist[i]);
    return ans;
}
#include "Baijan.h"
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>
#include <iostream>
#define fs first
#define se second

using namespace std;
typedef pair<int, int> pii;

namespace {

const int inf = 1e9;
const int non = 505;
int n;
vector<pii> edge[2000];
int dist[2000];
queue<int> r;
priority_queue<pii> q;
int mode, mx, nd, nx;
int sync[2000];

}  // namespace

static int get(int bit) {
    int ret = 0;
    for (int i = 0; i < bit; ++i) {
        if (r.front()) ret |= 1 << i;
        r.pop();
    }
    return ret;
}

static void send(int x, int bit) {
    while (bit--) {
        SendB(x & 1);
        x >>= 1;
    }
}

static void sendNext() {
    nd = non + mx;
    while (!q.empty()) {
        int d, x;
        tie(d, x) = q.top();
        d = -d;
        if (dist[x] != d) {
            q.pop();
            continue;
        }
        if (sync[x]) {
            q.pop();
            for (pii i : edge[x]) {
                if (sync[i.fs]) continue;
                if (dist[i.fs] <= dist[x] + i.se) continue;
                dist[i.fs] = dist[x] + i.se;
                q.emplace(-dist[i.fs], i.fs);
            }
            continue;
        }
        nd = d;
        nx = x;
        break;
    }
    nd -= mx;
    send(nd, 9);
}

void InitB(int N, int A, std::vector<int> U, std::vector<int> V,
           std::vector<int> C) {
    n = N;
    for (int i = 0; i < A; ++i) {
        edge[U[i]].emplace_back(V[i], C[i]);
        edge[V[i]].emplace_back(U[i], C[i]);
    }
    for (int i = 1; i < n; ++i) dist[i] = inf;
    q.emplace(0, 0);
    sync[0] = 1;
    sendNext();
}

static void pro1() {
    int bd = get(9);
    if (nd == non && bd == non) return;
    if (nd <= bd) {
        sync[nx] = 1;
        mx = dist[nx];
        send(nx, 11);
        sendNext();
    }
    else {
        mode = 1;
        mx += bd;
    }
}

static void pro2() {
    int bx = get(11);
    dist[bx] = mx;
    sync[bx] = 1;
    q.emplace(-dist[bx], bx);
    sendNext();
    mode = 0;
}

void ReceiveB(bool x) {
    r.push(x);
    if (mode == 0 && r.size() == 9) pro1();
    else if (mode == 1 && r.size() == 11) pro2();
}
# Verdict Execution time Memory Grader output
1 Correct 988 ms 1768 KB Output is correct
2 Correct 4 ms 984 KB Output is correct
3 Correct 1158 ms 1816 KB Output is correct
4 Correct 1292 ms 19800 KB Output is correct
5 Correct 54 ms 1760 KB Output is correct
6 Correct 1196 ms 4320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1192 KB Output is correct
2 Correct 1093 ms 1520 KB Output is correct
3 Correct 868 ms 1840 KB Output is correct
4 Correct 1216 ms 55080 KB Output is correct
5 Correct 1210 ms 48264 KB Output is correct
6 Correct 164 ms 1496 KB Output is correct
7 Correct 1432 ms 48192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 882 ms 1496 KB Output is correct
2 Correct 6 ms 1248 KB Output is correct
3 Correct 810 ms 1504 KB Output is correct
4 Correct 792 ms 1744 KB Output is correct
5 Correct 850 ms 1944 KB Output is correct
6 Correct 970 ms 1688 KB Output is correct
7 Correct 872 ms 1424 KB Output is correct
8 Correct 1032 ms 1576 KB Output is correct
9 Correct 1006 ms 1624 KB Output is correct
10 Correct 1168 ms 1464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 424 ms 1528 KB Output is correct
2 Correct 510 ms 1536 KB Output is correct
3 Correct 774 ms 23688 KB Output is correct
4 Correct 386 ms 1728 KB Output is correct
5 Correct 498 ms 17200 KB Output is correct
6 Correct 418 ms 1608 KB Output is correct
7 Correct 446 ms 1848 KB Output is correct
8 Correct 462 ms 1576 KB Output is correct
9 Correct 874 ms 35736 KB Output is correct
10 Correct 804 ms 35912 KB Output is correct
11 Correct 1248 ms 60952 KB Output is correct
12 Correct 1022 ms 53464 KB Output is correct
13 Correct 460 ms 1504 KB Output is correct
14 Correct 6 ms 1248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 424 ms 1528 KB Output is correct
2 Correct 510 ms 1536 KB Output is correct
3 Correct 774 ms 23688 KB Output is correct
4 Correct 386 ms 1728 KB Output is correct
5 Correct 498 ms 17200 KB Output is correct
6 Correct 418 ms 1608 KB Output is correct
7 Correct 446 ms 1848 KB Output is correct
8 Correct 462 ms 1576 KB Output is correct
9 Correct 874 ms 35736 KB Output is correct
10 Correct 804 ms 35912 KB Output is correct
11 Correct 1248 ms 60952 KB Output is correct
12 Correct 1022 ms 53464 KB Output is correct
13 Correct 460 ms 1504 KB Output is correct
14 Correct 6 ms 1248 KB Output is correct
15 Correct 548 ms 1816 KB Output is correct
16 Correct 546 ms 1568 KB Output is correct
17 Correct 472 ms 1480 KB Output is correct
18 Correct 754 ms 17776 KB Output is correct
19 Correct 568 ms 1680 KB Output is correct
20 Correct 728 ms 18040 KB Output is correct
21 Correct 464 ms 1576 KB Output is correct
22 Correct 830 ms 1656 KB Output is correct
23 Correct 1034 ms 43864 KB Output is correct
24 Correct 988 ms 44024 KB Output is correct
25 Correct 1410 ms 74984 KB Output is correct
26 Correct 1116 ms 63936 KB Output is correct
27 Correct 531 ms 1672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 424 ms 1528 KB Output is correct
2 Correct 510 ms 1536 KB Output is correct
3 Correct 774 ms 23688 KB Output is correct
4 Correct 386 ms 1728 KB Output is correct
5 Correct 498 ms 17200 KB Output is correct
6 Correct 418 ms 1608 KB Output is correct
7 Correct 446 ms 1848 KB Output is correct
8 Correct 462 ms 1576 KB Output is correct
9 Correct 874 ms 35736 KB Output is correct
10 Correct 804 ms 35912 KB Output is correct
11 Correct 1248 ms 60952 KB Output is correct
12 Correct 1022 ms 53464 KB Output is correct
13 Correct 460 ms 1504 KB Output is correct
14 Correct 6 ms 1248 KB Output is correct
15 Correct 548 ms 1816 KB Output is correct
16 Correct 546 ms 1568 KB Output is correct
17 Correct 472 ms 1480 KB Output is correct
18 Correct 754 ms 17776 KB Output is correct
19 Correct 568 ms 1680 KB Output is correct
20 Correct 728 ms 18040 KB Output is correct
21 Correct 464 ms 1576 KB Output is correct
22 Correct 830 ms 1656 KB Output is correct
23 Correct 1034 ms 43864 KB Output is correct
24 Correct 988 ms 44024 KB Output is correct
25 Correct 1410 ms 74984 KB Output is correct
26 Correct 1116 ms 63936 KB Output is correct
27 Correct 531 ms 1672 KB Output is correct
28 Correct 614 ms 2008 KB Output is correct
29 Correct 736 ms 1672 KB Output is correct
30 Correct 1162 ms 41976 KB Output is correct
31 Correct 802 ms 1312 KB Output is correct
32 Correct 1406 ms 37600 KB Output is correct
33 Correct 944 ms 1816 KB Output is correct
34 Correct 906 ms 1672 KB Output is correct
35 Correct 670 ms 1736 KB Output is correct
36 Correct 1262 ms 49576 KB Output is correct
37 Correct 1362 ms 49008 KB Output is correct
38 Correct 1486 ms 85216 KB Output is correct
39 Correct 1568 ms 78408 KB Output is correct
40 Correct 662 ms 1800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 988 ms 1768 KB Output is correct
2 Correct 4 ms 984 KB Output is correct
3 Correct 1158 ms 1816 KB Output is correct
4 Correct 1292 ms 19800 KB Output is correct
5 Correct 54 ms 1760 KB Output is correct
6 Correct 1196 ms 4320 KB Output is correct
7 Correct 8 ms 1192 KB Output is correct
8 Correct 1093 ms 1520 KB Output is correct
9 Correct 868 ms 1840 KB Output is correct
10 Correct 1216 ms 55080 KB Output is correct
11 Correct 1210 ms 48264 KB Output is correct
12 Correct 164 ms 1496 KB Output is correct
13 Correct 1432 ms 48192 KB Output is correct
14 Correct 882 ms 1496 KB Output is correct
15 Correct 6 ms 1248 KB Output is correct
16 Correct 810 ms 1504 KB Output is correct
17 Correct 792 ms 1744 KB Output is correct
18 Correct 850 ms 1944 KB Output is correct
19 Correct 970 ms 1688 KB Output is correct
20 Correct 872 ms 1424 KB Output is correct
21 Correct 1032 ms 1576 KB Output is correct
22 Correct 1006 ms 1624 KB Output is correct
23 Correct 1168 ms 1464 KB Output is correct
24 Correct 424 ms 1528 KB Output is correct
25 Correct 510 ms 1536 KB Output is correct
26 Correct 774 ms 23688 KB Output is correct
27 Correct 386 ms 1728 KB Output is correct
28 Correct 498 ms 17200 KB Output is correct
29 Correct 418 ms 1608 KB Output is correct
30 Correct 446 ms 1848 KB Output is correct
31 Correct 462 ms 1576 KB Output is correct
32 Correct 874 ms 35736 KB Output is correct
33 Correct 804 ms 35912 KB Output is correct
34 Correct 1248 ms 60952 KB Output is correct
35 Correct 1022 ms 53464 KB Output is correct
36 Correct 460 ms 1504 KB Output is correct
37 Correct 6 ms 1248 KB Output is correct
38 Correct 548 ms 1816 KB Output is correct
39 Correct 546 ms 1568 KB Output is correct
40 Correct 472 ms 1480 KB Output is correct
41 Correct 754 ms 17776 KB Output is correct
42 Correct 568 ms 1680 KB Output is correct
43 Correct 728 ms 18040 KB Output is correct
44 Correct 464 ms 1576 KB Output is correct
45 Correct 830 ms 1656 KB Output is correct
46 Correct 1034 ms 43864 KB Output is correct
47 Correct 988 ms 44024 KB Output is correct
48 Correct 1410 ms 74984 KB Output is correct
49 Correct 1116 ms 63936 KB Output is correct
50 Correct 531 ms 1672 KB Output is correct
51 Correct 614 ms 2008 KB Output is correct
52 Correct 736 ms 1672 KB Output is correct
53 Correct 1162 ms 41976 KB Output is correct
54 Correct 802 ms 1312 KB Output is correct
55 Correct 1406 ms 37600 KB Output is correct
56 Correct 944 ms 1816 KB Output is correct
57 Correct 906 ms 1672 KB Output is correct
58 Correct 670 ms 1736 KB Output is correct
59 Correct 1262 ms 49576 KB Output is correct
60 Correct 1362 ms 49008 KB Output is correct
61 Correct 1486 ms 85216 KB Output is correct
62 Correct 1568 ms 78408 KB Output is correct
63 Correct 662 ms 1800 KB Output is correct
64 Correct 1120 ms 1976 KB Output is correct
65 Correct 1162 ms 47088 KB Output is correct
66 Correct 1560 ms 40792 KB Output is correct
67 Correct 1052 ms 2232 KB Output is correct
68 Correct 1298 ms 2280 KB Output is correct
69 Correct 2028 ms 83032 KB Output is correct
70 Correct 1756 ms 68032 KB Output is correct
71 Correct 807 ms 9040 KB Output is correct
72 Correct 1074 ms 2344 KB Output is correct