Submission #1363360

#TimeUsernameProblemLanguageResultExecution timeMemory
1363360solution6312Broken Device (JOI17_broken_device)C++17
85 / 100
15 ms1548 KiB
#include "Annalib.h"
#include <iostream>
#include <cassert>
using namespace std;
using ll=long long;

void Set(int pos, int bit);
namespace encode
{
    int f[150], b3[38];
    void Anna(int N, ll X, int K, int P[])
    {
        for (int i=0; i<150; i++) f[i]=1;
        for (int i=0; i<K; i++) f[P[i]]=0;
        for (int i=0; i<38; i++)
        {
            b3[i]=X%3;
            X/=3;
        }
        int cnt=0;
        for (int i=0; i<150; i+=2)
        {
            if (!f[i] || !f[i+1] || cnt==38)
            {
                Set(i, 0);
                Set(i+1, 0);
                continue;
            }
            if (b3[cnt]==0)
            {
                Set(i, 0);
                Set(i+1, 1);
            }
            else if (b3[cnt]==1)
            {
                Set(i, 1);
                Set(i+1, 0);
            }
            else
            {
                Set(i, 1);
                Set(i+1, 1);
            }
            cnt++;
        }
    }
}
void Anna(int N, ll X, int K, int P[]) { encode::Anna(N, X, K, P); }
#include "Brunolib.h"
#include <iostream>
#include <cassert>
using namespace std;
using ll=long long;

namespace decode
{
    ll p3[38]; bool f=0;
    ll Bruno(int N, int A[])
    {
        if (!f)
        {
            p3[0]=1;
            for (int i=1; i<38; i++) p3[i]=p3[i-1]*3;
            f=1;
        }
        int cnt=0; ll ans=0;
        for (int i=0; i<150; i+=2)
        {
            if (!A[i] && !A[i+1]) continue;
            assert(cnt<38);
            if (A[i] && !A[i+1]) ans+=p3[cnt];
            else if (A[i] && A[i+1]) ans+=p3[cnt]*2;
            cnt++;
        }
        return ans;
    }
}
ll Bruno(int N, int A[]) { return decode::Bruno(N, A); }
#Result Execution timeMemoryGrader output
Fetching results...