Submission #1208873

#TimeUsernameProblemLanguageResultExecution timeMemory
1208873Zbyszek99Broken Device (JOI17_broken_device)C++20
100 / 100
37 ms1548 KiB
#include "Annalib.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

bool bad[150];
map<int,vi> mapa = {{0,{1,1,1}},{1,{0,0,1}},{2,{1,1,0}},{3,{0,1,1}}};

void Anna(int N, ll X, int K, int P[])
{
    vi bits(160,0);
    rep(bit,60)
    {
        if((1LL << (ll)bit) & X) bits[bit] = 1;
    }
    rep(i,150) bad[i] = 0;
    rep(i,K) bad[P[i]] = 1;
    int cur_bit = 0;
    rep3(bit,0,N-1,3)
    {
        int bad_cnt = 0;
        rep2(j,bit,bit+2) if(bad[j]) bad_cnt++;
        if(bad_cnt >= 2)
        {
            Set(bit,0);
            Set(bit+1,0);
            Set(bit+2,0);
        }
        else if(bad_cnt == 1)
        {
            int bb = 0;
            if(bad[bit+1]) bb = 1;
            if(bad[bit+2]) bb = 2;
            if(bb == 0)
            {
                if(bits[cur_bit] == 0)
                {
                    Set(bit,0);
                    Set(bit+1,1);
                    Set(bit+2,0);
                    cur_bit++;
                    continue;
                }
                if(bits[cur_bit+1] == 0)
                {
                    Set(bit,0);
                    Set(bit+1,0);
                    Set(bit+2,1);
                    cur_bit+=2;
                    continue;
                }
                else
                {
                    Set(bit,0);
                    Set(bit+1,1);
                    Set(bit+2,1);
                    cur_bit+=2;
                    continue;
                }
            }
            else if(bb == 1)
            {
                if(bits[cur_bit] == 0)
                {
                    Set(bit,1);
                    Set(bit+1,0);
                    Set(bit+2,1);
                    cur_bit++;
                    continue;
                }
                else
                {
                    Set(bit,1);
                    Set(bit+1,0);
                    Set(bit+2,0);
                    cur_bit++;
                    continue;
                }
            }
            else
            {
                if(bits[cur_bit] == 0)
                {
                    Set(bit,0);
                    Set(bit+1,1);
                    Set(bit+2,0);
                    cur_bit++;
                    continue;
                }
                else
                {
                    Set(bit,1);
                    Set(bit+1,0);
                    Set(bit+2,0);
                    cur_bit++;
                    continue;
                }
            }
        }
        else
        {
            int z = bits[cur_bit] + 2 * bits[cur_bit+1];
            cur_bit+=2;
            rep(j,3)
            {
                Set(bit+j,mapa[z][j]);
            }
        }
    }
}
#include "Brunolib.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

map<int,vi> m = {{0,{}},{1,{1}},{2,{0}},{3,{0,1}},{4,{1,0}},{5,{0}},{6,{1,1}},{7,{0,0}}};

ll Bruno(int N,int A[])
{
    vl bits(160,0);
    int cur_bit = 0;
    rep3(bit,0,N-1,3)
    {
        int z = A[bit] + 2 * A[bit+1] + 4 * A[bit+2];
        forall(it,m[z])
        {
            bits[cur_bit] = it;
            cur_bit++;
        }
    }
    ll x = 0;
    rep(bit,60)
    {
        x += (1LL << (ll)bit) * bits[bit];
    }
    return x;
}
#Verdict Execution timeMemoryGrader output
Fetching results...