Submission #983610

# Submission time Handle Problem Language Result Execution time Memory
983610 2024-05-15T18:58:01 Z Zbyszek99 Two Transportations (JOI19_transportations) C++17
0 / 100
1 ms 588 KB
#include <bits/stdc++.h>
#include "Azer.h"
#define ff first 
#define ss second
using namespace std;

struct Compare {
    bool operator()(pair<int,int> a, pair<int,int> b) {
        return a > b; 
    }
};

int GETTING_VAL= 0;
int GETTING_V = 1;

vector<int> ans;
int n,m;
vector<pair<int,int>> graf[2001];
bitset<2001> odw;
priority_queue<pair<int,int>, vector<pair<int,int>>, Compare> pri;
int akt_odl;
int oper;
int how_many_bits;
int num;
int new_v;
int tryb;

void SendNum(int x, int wiel)
{
    for(int bit = 0; bit < wiel; bit++)
    {
        if(x & (1 << bit))
        {
            SendA(1);
        }
        else
        {
            SendA(0);
        }
    }
}

void InitA(int N, int M, vector<int> U, vector<int> V, vector<int> cost)
{
    odw[0] = 1;
    ans[0] = 0;
    n = N;
    m = M;
    for(int i = 0; i < m; i++)
    {
        graf[U[i]].push_back({cost[i],V[i]});
        graf[V[i]].push_back({cost[i],U[i]});
    }
    for(auto& it: graf[0])
    {
        pri.push(it);
    }
    pair<int,int> t = pri.top();
    SendNum(t.ff - akt_odl,9);
}

void ReceiveA(bool x)
{
    if(tryb == GETTING_VAL)
    {
        if(x) num += (1 << how_many_bits);
        how_many_bits++;
        if(how_many_bits == 9)
        {
            oper++;
            if(oper == n-1) return;
            if(pri.top().ff - akt_odl <= num)
            {
                SendNum(pri.top().ss,11);
                akt_odl = pri.top().ff;
                ans[pri.top().ff] = akt_odl;
                for(auto& it: graf[pri.top().ss])
                {
                    if(odw[it.ss] == 0) 
                    {
                        pri.push({it.ff + akt_odl, it.ss});
                        odw[it.ss] = 1;
                    }
                }
                how_many_bits = 0;
                num = 0;
                pri.pop();
                SendNum(pri.top().ff - akt_odl,9); //only for Azer
            }
            else
            {
                new_v = 0;
                how_many_bits = 0;
                tryb = GETTING_V;
            }
        }
    }
    else
    {
        if(x) new_v += (1 << how_many_bits);
        how_many_bits++;
        if(how_many_bits == 11)
        {
            tryb = GETTING_VAL;
            ans[new_v] = akt_odl+num;
            akt_odl += num;
            odw[new_v] = 1;
            for(auto& it: graf[new_v])
            {
                if(odw[it.ss] == 0) 
                {
                    pri.push({it.ff + akt_odl, it.ss});
                    odw[it.ss] = 1;
                }
            }
            how_many_bits = 0;
            num = 0;
        }
    }
}

vector<int> Answer()
{
    return ans;
}
#include <bits/stdc++.h>
#include "Baijan.h"
#define ff first 
#define ss second
using namespace std;

struct Compare {
    bool operator()(pair<int,int> a, pair<int,int> b) {
        return a > b; 
    }
};

int GETTING_VAL= 0;
int GETTING_V = 1;

vector<int> ans;
int n,m;
vector<pair<int,int>> graf[2001];
bitset<2001> odw;
priority_queue<pair<int,int>, vector<pair<int,int>>, Compare> pri;
int akt_odl;
int oper;
int how_many_bits;
int num;
int new_v;
int tryb;

void SendNum(int x, int wiel)
{
    for(int bit = 0; bit < wiel; bit++)
    {
        if(x & (1 << bit))
        {
            SendB(1);
        }
        else
        {
            SendB(0);
        }
    }
}

void InitB(int N, int M, vector<int> U, vector<int> V, vector<int> cost)
{
    odw[0] = 1;
    ans[0] = 0;
    n = N;
    m = M;
    for(int i = 0; i < m; i++)
    {
        graf[U[i]].push_back({cost[i],V[i]});
        graf[V[i]].push_back({cost[i],U[i]});
    }
    for(auto& it: graf[0])
    {
        pri.push(it);
    }
    pair<int,int> t = pri.top();
    SendNum(t.ff - akt_odl,9);
}

void ReceiveB(bool x)
{
    if(tryb == GETTING_VAL)
    {
        if(x) num += (1 << how_many_bits);
        how_many_bits++;
        if(how_many_bits == 9)
        {
            oper++;
            if(oper == n-1) return;
            if(pri.top().ff - akt_odl <= num)
            {
                SendNum(pri.top().ss,11);
                akt_odl = pri.top().ff;
                ans[pri.top().ff] = akt_odl;
                for(auto& it: graf[pri.top().ss])
                {
                    if(odw[it.ss] == 0) 
                    {
                        pri.push({it.ff + akt_odl, it.ss});
                        odw[it.ss] = 1;
                    }
                }
                how_many_bits = 0;
                num = 0;
                pri.pop();
               // SendNum(pri.top().ff - akt_odl,9); //only for Azer
            }
            else
            {
                new_v = 0;
                how_many_bits = 0;
                tryb = GETTING_V;
            }
        }
    }
    else
    {
        if(x) new_v += (1 << how_many_bits);
        how_many_bits++;
        if(how_many_bits == 11)
        {
            tryb = GETTING_VAL;
            ans[new_v] = akt_odl+num;
            akt_odl += num;
            odw[new_v] = 1;
            for(auto& it: graf[new_v])
            {
                if(odw[it.ss] == 0) 
                {
                    pri.push({it.ff + akt_odl, it.ss});
                    odw[it.ss] = 1;
                }
            }
            how_many_bits = 0;
            num = 0;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -