Submission #119958

# Submission time Handle Problem Language Result Execution time Memory
119958 2019-06-22T18:01:43 Z duality Two Transportations (JOI19_transportations) C++14
100 / 100
2630 ms 85296 KB
#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#include "Azer.h"

namespace {
    int N;
    vpii adjList[2000];
    int dist[2000],done[2000];
    int num,c = 0,s = 0,l = 0,r,logr;
}

void InitA(int N,int A,vector<int> U,vector<int> V,vector<int> C) {
    int i;
    ::N = N;
    for (i = 0; i < N; i++) dist[i] = (1 << 20)-1,done[i] = 0;
    for (i = 0; i < A; i++) {
        adjList[U[i]].pb(mp(V[i],C[i]));
        adjList[V[i]].pb(mp(U[i],C[i]));
    }
    dist[0] = 0,done[0] = 1,r = N,logr = 1;
    while ((1 << logr) < r) logr++;
    for (i = 0; i < adjList[0].size(); i++) dist[adjList[0][i].first] = adjList[0][i].second;
}
void ReceiveA(bool x) {
    int i,m = -1;
    for (i = 0; i < N; i++) {
        if (!done[i] && ((m == -1) || (dist[i] < dist[m]))) m = i;
    }
    if (m == -1) return;
    if (s == 0) {
        if (dist[m] == ((1 << 20)-1)) {
            for (i = 0; i < 9; i++) SendA(1);
        }
        else {
            for (i = 0; i < 9; i++) SendA(((dist[m]-l) >> i) & 1);
        }
        s = 1;
    }
    else if (s == 1) {
        if (x == 0) s = 2;
        else {
            int u = 0;
            for (i = 0; i < m; i++) {
                if (!done[i]) u++;
            }
            for (i = 0; i < logr; i++) SendA((u >> i) & 1);
            l = dist[m];
            s = 3;
        }
    }
    else if (s == 2) {
        num |= (x << c),c++;
        if (c == 9+logr) {
            int u = num >> 9;
            for (i = 0; i < N; i++) {
                if (!done[i]) {
                    if (u == 0) break;
                    else u--;
                }
            }
            u = i;
            dist[u] = (num & ((1 << 9)-1))+l;
            l += (num & ((1 << 9)-1)),s = 3;
            m = u;
            c = num = 0;
        }
    }
    if (s == 3) {
        done[m] = 1;
        for (i = 0; i < adjList[m].size(); i++) {
            int v = adjList[m][i].first;
            dist[v] = min(dist[v],dist[m]+adjList[m][i].second);
        }
        r--;
        if ((logr > 0) && ((1 << (logr-1)) >= r)) logr--;
        s = 0;

        m = -1;
        for (i = 0; i < N; i++) {
            if (!done[i] && ((m == -1) || (dist[i] < dist[m]))) m = i;
        }
        if (m == -1) return;
        if (dist[m] == ((1 << 20)-1)) {
            for (i = 0; i < 9; i++) SendA(1);
        }
        else {
            for (i = 0; i < 9; i++) SendA(((dist[m]-l) >> i) & 1);
        }
        s = 1;
    }
}
vector<int> Answer() {
    int i;
    vi ans;
    for (i = 0; i < N; i++) ans.pb(dist[i]);
    return ans;
}
#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#include "Baijan.h"

namespace {
    int N;
    vpii adjList[2000];
    int dist[2000],done[2000];
    int num,c = 0,s = 0,l = 0,r,logr;
}

void InitB(int N,int B,vector<int> S,vector<int> T,vector<int> D) {
    int i;
    ::N = N;
    for (i = 0; i < N; i++) dist[i] = (1 << 20)-1,done[i] = 0;
    for (i = 0; i < B; i++) {
        adjList[S[i]].pb(mp(T[i],D[i]));
        adjList[T[i]].pb(mp(S[i],D[i]));
    }
    dist[0] = 0,done[0] = 1,r = N,logr = 1;
    while ((1 << logr) < r) logr++;
    for (i = 0; i < adjList[0].size(); i++) dist[adjList[0][i].first] = adjList[0][i].second;
    SendB(0);
}
void ReceiveB(bool y) {
    int i,m = -1;
    for (i = 0; i < N; i++) {
        if (!done[i] && ((m == -1) || (dist[i] < dist[m]))) m = i;
    }
    if (s == 0) {
        num |= (y << c),c++;
        if (c == 9) {
            if ((l+(num & ((1 << 9)-1))) < dist[m]) SendB(1),s = 1;
            else {
                SendB(0);
                for (i = 0; i < 9; i++) SendB(((dist[m]-l) >> i) & 1);
                int u = 0;
                for (i = 0; i < m; i++) {
                    if (!done[i]) u++;
                }
                for (i = 0; i < logr; i++) SendB((u >> i) & 1);
                l = dist[m];
                s = 3;
                c = num = 0;
            }
        }
    }
    else if (s == 1) {
        num |= (y << c),c++;
        if (c == 9+logr) {
            int u = num >> 9;
            for (i = 0; i < N; i++) {
                if (!done[i]) {
                    if (u == 0) break;
                    else u--;
                }
            }
            u = i;
            dist[u] = (num & ((1 << 9)-1))+l;
            l += (num & ((1 << 9)-1)),s = 3;
            m = u;
            c = num = 0;
        }
    }
    if (s == 3) {
        done[m] = 1;
        for (i = 0; i < adjList[m].size(); i++) {
            int v = adjList[m][i].first;
            dist[v] = min(dist[v],dist[m]+adjList[m][i].second);
        }
        r--;
        if ((logr > 0) && ((1 << (logr-1)) >= r)) logr--;
        s = 0;
    }
}

Compilation message

Azer.cpp: In function 'void InitA(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
Azer.cpp:76:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[0].size(); i++) dist[adjList[0][i].first] = adjList[0][i].second;
                 ~~^~~~~~~~~~~~~~~~~~~
Azer.cpp: In function 'void ReceiveA(bool)':
Azer.cpp:124:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < adjList[m].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~~~

Baijan.cpp: In function 'void InitB(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
Baijan.cpp:76:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[0].size(); i++) dist[adjList[0][i].first] = adjList[0][i].second;
                 ~~^~~~~~~~~~~~~~~~~~~
Baijan.cpp: In function 'void ReceiveB(bool)':
Baijan.cpp:121:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < adjList[m].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1422 ms 1592 KB Output is correct
2 Correct 8 ms 1480 KB Output is correct
3 Correct 1621 ms 1552 KB Output is correct
4 Correct 1812 ms 20256 KB Output is correct
5 Correct 61 ms 1608 KB Output is correct
6 Correct 1520 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1264 KB Output is correct
2 Correct 1274 ms 1672 KB Output is correct
3 Correct 1160 ms 2072 KB Output is correct
4 Correct 1616 ms 55184 KB Output is correct
5 Correct 1455 ms 48064 KB Output is correct
6 Correct 158 ms 1504 KB Output is correct
7 Correct 1632 ms 48256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1398 ms 1496 KB Output is correct
2 Correct 4 ms 1192 KB Output is correct
3 Correct 1718 ms 1504 KB Output is correct
4 Correct 1572 ms 1512 KB Output is correct
5 Correct 1610 ms 1864 KB Output is correct
6 Correct 1296 ms 1224 KB Output is correct
7 Correct 1358 ms 1504 KB Output is correct
8 Correct 1588 ms 1760 KB Output is correct
9 Correct 1648 ms 1600 KB Output is correct
10 Correct 1772 ms 1520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 448 ms 1392 KB Output is correct
2 Correct 632 ms 1416 KB Output is correct
3 Correct 732 ms 23624 KB Output is correct
4 Correct 590 ms 1352 KB Output is correct
5 Correct 626 ms 17432 KB Output is correct
6 Correct 452 ms 1504 KB Output is correct
7 Correct 336 ms 1520 KB Output is correct
8 Correct 430 ms 1432 KB Output is correct
9 Correct 705 ms 35824 KB Output is correct
10 Correct 778 ms 35840 KB Output is correct
11 Correct 1182 ms 61128 KB Output is correct
12 Correct 1077 ms 53616 KB Output is correct
13 Correct 380 ms 1432 KB Output is correct
14 Correct 4 ms 1248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 448 ms 1392 KB Output is correct
2 Correct 632 ms 1416 KB Output is correct
3 Correct 732 ms 23624 KB Output is correct
4 Correct 590 ms 1352 KB Output is correct
5 Correct 626 ms 17432 KB Output is correct
6 Correct 452 ms 1504 KB Output is correct
7 Correct 336 ms 1520 KB Output is correct
8 Correct 430 ms 1432 KB Output is correct
9 Correct 705 ms 35824 KB Output is correct
10 Correct 778 ms 35840 KB Output is correct
11 Correct 1182 ms 61128 KB Output is correct
12 Correct 1077 ms 53616 KB Output is correct
13 Correct 380 ms 1432 KB Output is correct
14 Correct 4 ms 1248 KB Output is correct
15 Correct 568 ms 1760 KB Output is correct
16 Correct 460 ms 1760 KB Output is correct
17 Correct 514 ms 1400 KB Output is correct
18 Correct 702 ms 17712 KB Output is correct
19 Correct 522 ms 1536 KB Output is correct
20 Correct 744 ms 18080 KB Output is correct
21 Correct 640 ms 1544 KB Output is correct
22 Correct 596 ms 1760 KB Output is correct
23 Correct 830 ms 43976 KB Output is correct
24 Correct 1154 ms 43688 KB Output is correct
25 Correct 1480 ms 75096 KB Output is correct
26 Correct 1182 ms 64312 KB Output is correct
27 Correct 588 ms 1496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 448 ms 1392 KB Output is correct
2 Correct 632 ms 1416 KB Output is correct
3 Correct 732 ms 23624 KB Output is correct
4 Correct 590 ms 1352 KB Output is correct
5 Correct 626 ms 17432 KB Output is correct
6 Correct 452 ms 1504 KB Output is correct
7 Correct 336 ms 1520 KB Output is correct
8 Correct 430 ms 1432 KB Output is correct
9 Correct 705 ms 35824 KB Output is correct
10 Correct 778 ms 35840 KB Output is correct
11 Correct 1182 ms 61128 KB Output is correct
12 Correct 1077 ms 53616 KB Output is correct
13 Correct 380 ms 1432 KB Output is correct
14 Correct 4 ms 1248 KB Output is correct
15 Correct 568 ms 1760 KB Output is correct
16 Correct 460 ms 1760 KB Output is correct
17 Correct 514 ms 1400 KB Output is correct
18 Correct 702 ms 17712 KB Output is correct
19 Correct 522 ms 1536 KB Output is correct
20 Correct 744 ms 18080 KB Output is correct
21 Correct 640 ms 1544 KB Output is correct
22 Correct 596 ms 1760 KB Output is correct
23 Correct 830 ms 43976 KB Output is correct
24 Correct 1154 ms 43688 KB Output is correct
25 Correct 1480 ms 75096 KB Output is correct
26 Correct 1182 ms 64312 KB Output is correct
27 Correct 588 ms 1496 KB Output is correct
28 Correct 898 ms 1408 KB Output is correct
29 Correct 1082 ms 1504 KB Output is correct
30 Correct 1426 ms 42056 KB Output is correct
31 Correct 1114 ms 1136 KB Output is correct
32 Correct 1076 ms 37352 KB Output is correct
33 Correct 826 ms 1536 KB Output is correct
34 Correct 756 ms 1688 KB Output is correct
35 Correct 1024 ms 1656 KB Output is correct
36 Correct 1188 ms 49320 KB Output is correct
37 Correct 1366 ms 49072 KB Output is correct
38 Correct 1778 ms 85296 KB Output is correct
39 Correct 1480 ms 78352 KB Output is correct
40 Correct 854 ms 1752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1422 ms 1592 KB Output is correct
2 Correct 8 ms 1480 KB Output is correct
3 Correct 1621 ms 1552 KB Output is correct
4 Correct 1812 ms 20256 KB Output is correct
5 Correct 61 ms 1608 KB Output is correct
6 Correct 1520 ms 4344 KB Output is correct
7 Correct 8 ms 1264 KB Output is correct
8 Correct 1274 ms 1672 KB Output is correct
9 Correct 1160 ms 2072 KB Output is correct
10 Correct 1616 ms 55184 KB Output is correct
11 Correct 1455 ms 48064 KB Output is correct
12 Correct 158 ms 1504 KB Output is correct
13 Correct 1632 ms 48256 KB Output is correct
14 Correct 1398 ms 1496 KB Output is correct
15 Correct 4 ms 1192 KB Output is correct
16 Correct 1718 ms 1504 KB Output is correct
17 Correct 1572 ms 1512 KB Output is correct
18 Correct 1610 ms 1864 KB Output is correct
19 Correct 1296 ms 1224 KB Output is correct
20 Correct 1358 ms 1504 KB Output is correct
21 Correct 1588 ms 1760 KB Output is correct
22 Correct 1648 ms 1600 KB Output is correct
23 Correct 1772 ms 1520 KB Output is correct
24 Correct 448 ms 1392 KB Output is correct
25 Correct 632 ms 1416 KB Output is correct
26 Correct 732 ms 23624 KB Output is correct
27 Correct 590 ms 1352 KB Output is correct
28 Correct 626 ms 17432 KB Output is correct
29 Correct 452 ms 1504 KB Output is correct
30 Correct 336 ms 1520 KB Output is correct
31 Correct 430 ms 1432 KB Output is correct
32 Correct 705 ms 35824 KB Output is correct
33 Correct 778 ms 35840 KB Output is correct
34 Correct 1182 ms 61128 KB Output is correct
35 Correct 1077 ms 53616 KB Output is correct
36 Correct 380 ms 1432 KB Output is correct
37 Correct 4 ms 1248 KB Output is correct
38 Correct 568 ms 1760 KB Output is correct
39 Correct 460 ms 1760 KB Output is correct
40 Correct 514 ms 1400 KB Output is correct
41 Correct 702 ms 17712 KB Output is correct
42 Correct 522 ms 1536 KB Output is correct
43 Correct 744 ms 18080 KB Output is correct
44 Correct 640 ms 1544 KB Output is correct
45 Correct 596 ms 1760 KB Output is correct
46 Correct 830 ms 43976 KB Output is correct
47 Correct 1154 ms 43688 KB Output is correct
48 Correct 1480 ms 75096 KB Output is correct
49 Correct 1182 ms 64312 KB Output is correct
50 Correct 588 ms 1496 KB Output is correct
51 Correct 898 ms 1408 KB Output is correct
52 Correct 1082 ms 1504 KB Output is correct
53 Correct 1426 ms 42056 KB Output is correct
54 Correct 1114 ms 1136 KB Output is correct
55 Correct 1076 ms 37352 KB Output is correct
56 Correct 826 ms 1536 KB Output is correct
57 Correct 756 ms 1688 KB Output is correct
58 Correct 1024 ms 1656 KB Output is correct
59 Correct 1188 ms 49320 KB Output is correct
60 Correct 1366 ms 49072 KB Output is correct
61 Correct 1778 ms 85296 KB Output is correct
62 Correct 1480 ms 78352 KB Output is correct
63 Correct 854 ms 1752 KB Output is correct
64 Correct 1290 ms 2032 KB Output is correct
65 Correct 2264 ms 47064 KB Output is correct
66 Correct 1914 ms 40840 KB Output is correct
67 Correct 1562 ms 1872 KB Output is correct
68 Correct 1480 ms 2024 KB Output is correct
69 Correct 2630 ms 83112 KB Output is correct
70 Correct 2076 ms 67824 KB Output is correct
71 Correct 1416 ms 9016 KB Output is correct
72 Correct 1292 ms 2296 KB Output is correct