Submission #787152

# Submission time Handle Problem Language Result Execution time Memory
787152 2023-07-18T21:27:58 Z oscar1f Two Transportations (JOI19_transportations) C++17
0 / 100
7 ms 328 KB
#include "Azer.h"
#include<bits/stdc++.h>
using namespace std;

int nbSomA,nbAreA,INFINIA=1000*1000*1000,numAppelA=0,tempA,dernDistA=0,nbFiniA=1,recevDistA=0;
vector<int> repA,debA,finA,prixA,distA;
vector<pair<int,int>> adjaA[2005];

void envoiA(int x) {
    if (x==0) {
        SendA(false);
    }
    else {
        SendA(true);
    }
}

int transfoA(bool x) {
    if (x==true) {
        return 1;
    }
    return 0;
}

void decompoA(int val,int nbBits) {
    for (int i=0;i<nbBits;i++) {
        envoiA(val%2);
        val/=2;
    }
}

void calcMeilA(int propDistA) {
    int posMeilA=0,distMeilA=INFINIA;
    for (int i=0;i<nbSomA;i++) {
        if (distA[i]!=-1) {
            while (!adjaA[i].empty() and distA[adjaA[i].back().first]!=-1) {
                //cout<<posMeil<<" "<<distMeil<<endl;
                adjaA[i].pop_back();
            }
            if (!adjaA[i].empty() and distA[i]+adjaA[i].back().second<distMeilA) {
                distMeilA=distA[i]+adjaA[i].back().second;
                posMeilA=adjaA[i].back().first;
            }
        }
    }
    //cout<<"A : "<<posMeil<<" "<<distMeil<<endl;
    if (distMeilA>=propDistA) {
        recevDistA=1;
        decompoA(propDistA-dernDistA,9);
        dernDistA=propDistA;
    }
    else {
        decompoA(distMeilA-dernDistA,9);
        dernDistA=distMeilA;
        distA[posMeilA]=distMeilA;
        nbFiniA++;
        if (nbFiniA==nbSomA) {
            repA=distA;
        }
        decompoA(posMeilA,11);   
    }
}

void InitA(int N, int A, vector<int> U, vector<int> V, vector<int> C) {
    nbSomA=N;
    nbAreA=A;
    debA=U;
    finA=V;
    prixA=C;
    for (int i=0;i<nbAreA;i++) {
        adjaA[debA[i]].push_back({finA[i],prixA[i]});
        adjaA[finA[i]].push_back({debA[i],prixA[i]});
    }
    for (int i=0;i<nbSomA;i++) {
        sort(adjaA[i].begin(),adjaA[i].end(),[](pair<int,int> a,pair<int,int> b) {
            if (a.second>b.second) {
                return true;
            }
            return false;
        });
        /*for (auto j:adja[i]) {
            cout<<j.first<<" "<<j.second<<"   ";
        }
        cout<<endl;*/
    }
    distA.push_back(0);
    for (int i=1;i<nbSomA;i++) {
        distA.push_back(-1);
    }    
}

void ReceiveA(bool x) {
    if (recevDistA==0) {
        tempA+=transfoA(x)*(1<<(numAppelA));
        numAppelA++;
        if (numAppelA==9) {
            if (tempA!=0) {
                int distMeilA=tempA+dernDistA;
                //cout<<posMeil<<" "<<distMeil<<endl;
                calcMeilA(distMeilA);
            }
            else {
                calcMeilA(INFINIA);
            }
            tempA=0;
            numAppelA=0;
        }
    }
    else {
        tempA+=transfoA(x)*(1<<(numAppelA));
        numAppelA++;
        if (numAppelA==11) {
            distA[tempA]=dernDistA;
            nbFiniA++;
            if (nbFiniA==nbSomA) {
                repA=distA;
            }
            tempA=0;
            numAppelA=0;
            recevDistA=0;
        }
    }
}

vector<int> Answer() {
    /*for (int i:rep) {
        cout<<i<<" ";
    }
    cout<<endl;*/
    return repA;
}


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

int nbSomB,nbAreB,INFINIB=1000*1000*1000,numAppelB,tempB,dernDistB=0,recevDistB=0,propDistB,propPosB;
vector<int> repB,debB,finB,prixB,distB;
vector<pair<int,int>> adjaB[2005];

void envoiB(int x) {
    if (x==0) {
        SendB(false);
    }
    else {
        SendB(true);
    }
}

int transfoB(bool x) {
    if (x==true) {
        return 1;
    }
    return 0;
}

void decompoB(int val,int nbBits) {
    for (int i=0;i<nbBits;i++) {
        envoiB(val%2);
        val/=2;
    }
}

void calcMeilB() {
    int posMeilB=0,distMeilB=INFINIB;
    for (int i=0;i<nbSomB;i++) {
        if (distB[i]!=-1) {
            while (!adjaB[i].empty() and distB[adjaB[i].back().first]!=-1) {
                adjaB[i].pop_back();
            }
            if (!adjaB[i].empty() and distB[i]+adjaB[i].back().second<distMeilB) {
                distMeilB=distB[i]+adjaB[i].back().second;
                posMeilB=adjaB[i].back().first;
            }
        }
    }
    propDistB=distMeilB;
    propPosB=posMeilB;
    if (distMeilB==INFINIB or distMeilB>dernDistB+500) {
        distMeilB=0;
        posMeilB=0;
    }
    else {
        distMeilB-=dernDistB;
    }
    //cout<<"B : "<<posMeil<<" "<<distMeil<<endl;
    decompoB(distMeilB,9);
}

void InitB(int N, int B, vector<int> S, vector<int> T, vector<int> D) {
    nbSomB=N;
    nbAreB=B;
    debB=S;
    finB=T;
    prixB=D;
    for (int i=0;i<nbAreB;i++) {
        adjaB[debB[i]].push_back({finB[i],prixB[i]});
        adjaB[finB[i]].push_back({debB[i],prixB[i]});
    }
    for (int i=0;i<nbSomB;i++) {
        sort(adjaB[i].begin(),adjaB[i].end(),[](pair<int,int> a,pair<int,int> b) {
            if (a.second>b.second) {
                return true;
            }
            return false;
        });
    }
    distB.push_back(0);
    for (int i=1;i<nbSomB;i++) {
        distB.push_back(-1);
    }
    calcMeilB();
}

void ReceiveB(bool x) {
    if (recevDistB==0) {
        tempB+=transfoB(x)*(1<<numAppelB);
        numAppelB++;
        if (numAppelB==9) {
            int distMeilB=tempB+dernDistB;
            dernDistB=distMeilB;
            tempB=0;
            numAppelB=0;
            if (distMeilB==propDistB) {
                distB[propPosB]=propDistB;
                decompoB(propPosB,11);
                calcMeilB();
            }
            else {
                recevDistB=1;
            }
            //cout<<posMeil<<" "<<distMeil<<endl;
        }
    }
    else {
        tempB+=transfoB(x)*(1<<numAppelB);
        numAppelB++;
        if (numAppelB==11) {
            distB[tempB]=dernDistB;
            numAppelB=0;
            tempB=0;
            recevDistB=0;
            calcMeilB();
        }
    }
}

# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 328 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 328 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 328 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 328 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 328 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 328 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 328 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -