Submission #1218004

#TimeUsernameProblemLanguageResultExecution timeMemory
1218004GrayBroken Device (JOI17_broken_device)C++20
100 / 100
24 ms1552 KiB
#include "Annalib.h"
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;

void Anna( int N, long long X, int K, int P[] ){
    map<ll, ll> unfree;
    for (ll i=0; i<K; i++){
        unfree[P[i]]=1;
    }
    vector<ll> nums;
    for (ll i=0; i<60; i++){
        if ((1ull<<i)&X) nums.push_back(1);
        else nums.push_back(0);
    }
    reverse(nums.begin(), nums.end());
    for (ll i=2; i<N; i+=3){
      ll m2, m1;
      if (nums.empty()){
        m2=m1=0;
      }else{
        m1=nums.back(); nums.pop_back();
        if (nums.empty()) m2=0;
        else {
          m2=nums.back(); nums.pop_back();
        }
      }
      if (unfree.count(i)+unfree.count(i-1)+unfree.count(i-2)>=2){
          Set(i-2, 0); Set(i-1, 0); Set(i, 0); nums.push_back(m2); nums.push_back(m1);
      }else{
          if (m1==0){
              if (m2==0 and !unfree.count(i-1)){
                  Set(i-1, 1); Set(i-2, 0); Set(i, 0);
              }else if (m2==1 and !unfree.count(i-1) and !unfree.count(i)){
                  Set(i, 1); Set(i-1, 1); Set(i-2, 0);
                }else{
                    Set(i-2, 1); Set(i, 0); Set(i-1, 0);
                    nums.push_back(m2);
                }
            }else{
                if (m2==0 and !unfree.count(i-2) and !unfree.count(i)){
                    Set(i-2, 1); Set(i, 1); Set(i-1, 0);
                }else if (m2==1 and !unfree.count(i) and !unfree.count(i-1) and !unfree.count(i-2)){
                    Set(i-2, 1); Set(i-1, 1); Set(i, 1);
                }else{
                    if (unfree.count(i)){
                        Set(i-1, 1); Set(i-2, 1); Set(i, 0);
                    }else{
                        Set(i, 1); Set(i-2, 0); Set(i-1, 0);
                    }
                    nums.push_back(m2);
                }
            }
        }
    }
}
/*

0 -> 100
00 > 010
01 -> 011

1 -> 001 || 110
10 -> 101
11 -> 111
01110000
*/
#include "Brunolib.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;

long long Bruno( int N, int A[] ){
    vector<ll> nums;
    // for (ll i=0; i<N; i++) cout << A[i] << endl;
    for (ll i=2; i<N and nums.size()<60; i+=3){
        if (A[i]==0 and A[i-1]==0 and A[i-2]==0) continue;
        else{
            if (A[i-2]==1 and A[i-1]==0 and A[i]==0) nums.push_back(0);
            else if (A[i]==0 and A[i-1]==1 and A[i-2]==0) {
                nums.push_back(0); 
                nums.push_back(0);
            } else if (A[i]==1 and A[i-1]==1 and A[i-2]==0){
                nums.push_back(0);
                nums.push_back(1);
            }else if (A[i]==1 and A[i-2]==1 and A[i-1]==0){
                nums.push_back(1); 
                nums.push_back(0);
            }else if (A[i] and A[i-1] and A[i-2]){
                nums.push_back(1);
                nums.push_back(1);
            }else{
                nums.push_back(1);
            }
        }
    }
    ll x=0;
    for (ll i=0; i<60; i++){
        if (nums[i]) x+=(1ull<<i);
    }
  return x;
}
#Verdict Execution timeMemoryGrader output
Fetching results...