Submission #1078974

#TimeUsernameProblemLanguageResultExecution timeMemory
1078974veehjBroken Device (JOI17_broken_device)C++17
100 / 100
33 ms3260 KiB
#include "Annalib.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (ll) a.size()
#define all(x) (x).begin(), (x).end()

void Anna( int N, long long X, int K, int P[] ){
  set<int> err={};
  ll x=X;
  for(int i=0; i<K; i++) err.insert(P[i]);
  for(int i=0; i<N; i+=3){
    int cnt=err.count(i)+err.count(i+1)+err.count(i+2);
    if(cnt>=2 || x==0){
      Set(i, 0), Set(i+1, 0), Set(i+2, 0);
      continue;
    }
    if(cnt==0){
      int mre=x%4;
      x/=4;
      if(mre==0) Set(i, 1), Set(i+1, 0), Set(i+2, 0);
      if(mre==1) Set(i, 0), Set(i+1, 1), Set(i+2, 1);
      if(mre==2) Set(i, 1), Set(i+1, 0), Set(i+2, 1);
      if(mre==3) Set(i, 1), Set(i+1, 1), Set(i+2, 1);
    }
    if(cnt==1){
      if(x%2){
        if(err.count(i+2)) Set(i, 1), Set(i+1, 1), Set(i+2, 0);
        else Set(i, 0), Set(i+1, 0), Set(i+2, 1);
        x/=2;
      } else {
        if(err.count(i+1)){
          int mre=x%4;
          x/=4;
          if(mre==0) Set(i, 1), Set(i+1, 0), Set(i+2, 0);
          if(mre==2) Set(i, 1), Set(i+1, 0), Set(i+2, 1);
        } else {
          Set(i, 0), Set(i+1, 1), Set(i+2, 0);
          x/=2;
        }
      }
    }
  }
}
#include "Brunolib.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (ll) a.size()
#define all(x) (x).begin(), (x).end()

long long Bruno( int N, int A[] ){
  ll ans=0;
  stack<int> st;
  for(int i=0; i<N; i+=3){
    int curr=A[i]*4+A[i+1]*2+A[i+2];
    if(curr==0) continue;
    if(curr==1) st.push(1);
    if(curr==2) st.push(0);
    if(curr==3) st.push(1), st.push(0);
    if(curr==4) st.push(0), st.push(0);
    if(curr==5) st.push(0), st.push(1);
    if(curr==6) st.push(1);
    if(curr==7) st.push(1), st.push(1);
  }
  while(!st.empty()){
    ans*=2;
    ans+=st.top();
    st.pop();
  }
  return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...