Submission #427003

#TimeUsernameProblemLanguageResultExecution timeMemory
427003tqbfjotldCity (JOI17_city)C++14
22 / 100
929 ms65268 KiB
#include "Encoder.h"
#include <bits/stdc++.h>
using namespace std;

int lch[500005];
int rch[500005];
int curnodes,n;
vector<int> adjl[250005];

int func(int node, int pa){
    set<pair<int,int> > stuff;
    for (auto x : adjl[node]){
        if (x==pa) continue;
        int res = func(x,node);
        stuff.insert({res,x});
    }
    while (stuff.size()>2){
        auto i1 = *stuff.begin();
        stuff.erase(stuff.begin());
        auto i2 = *stuff.begin();
        stuff.erase(stuff.begin());
        int nw = curnodes++;
        lch[nw] = i1.second;
        rch[nw] = i2.second;
        stuff.insert({i2.first+1,nw});
    }
    if (stuff.size()==2){
        auto i1 = *stuff.begin();
        stuff.erase(stuff.begin());
        auto i2 = *stuff.begin();
        stuff.erase(stuff.begin());
        lch[node] = i1.second;
        rch[node] = i2.second;
        return i2.first+1;
    }
    if (stuff.size()==1){
        auto i1 = *stuff.begin();
        lch[node] = i1.second;
        return i1.first+1;
    }
    return 0;
}

void dfs2(int node, long long curamt, int pos){
    //printf("ch of %d = %d %d\n",node,lch[node],rch[node]);
    if (node<n){
       // printf("code %d %lld\n",node,curamt+(1LL<<pos));
        Code(node,curamt+(1LL<<pos));
    }
    if (lch[node]!=-1){
        dfs2(lch[node],curamt,pos+1);
    }
    if (rch[node]!=-1){
        dfs2(rch[node],curamt+(1LL<<pos),pos+1);
    }
}

void Encode(int N, int A[], int B[])
{
    n = N;
    memset(lch,-1,sizeof(lch));
    memset(rch,-1,sizeof(rch));
    curnodes = N;
    for (int x = 0; x<N-1; x++){
        adjl[A[x]].push_back(B[x]);
        adjl[B[x]].push_back(A[x]);
    }
    func(0,-1);
    dfs2(0,0,0);
}
#include "Device.h"
#include <bits/stdc++.h>
using namespace std;

void InitDevice()
{
}

int Answer(long long S, long long T)
{
    string s1,s2;
    for (int x = 0; x<64; x++){
        if (S)s1.push_back((S&1)?'1':'0');
        S>>=1;
        if (T)s2.push_back((T&1)?'1':'0');
        T>>=1;
    }
    s1.pop_back();
    s2.pop_back();
    //printf("cmp %s %s\n",s1.c_str(),s2.c_str());
    if (s1.size()<s2.size()){
        for (int x = 0; x<s1.size(); x++){
            if (s1[x]!=s2[x]) return 2;
        }
        return 1;
    }
    for (int x = 0; x<s2.size(); x++){
        if (s1[x]!=s2[x]) return 2;
    }
	return 0;
}

Compilation message (stderr)

Device.cpp: In function 'int Answer(long long int, long long int)':
Device.cpp:22:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for (int x = 0; x<s1.size(); x++){
      |                         ~^~~~~~~~~~
Device.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int x = 0; x<s2.size(); x++){
      |                     ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...