제출 #1324136

#제출 시각아이디문제언어결과실행 시간메모리
1324136SmuggingSpunBroken Device (JOI17_broken_device)C++20
100 / 100
25 ms1580 KiB
#include "Annalib.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void Anna(int n, ll x, int k, int pd[]){
  vector<bool>c(n, true), send(n, false);
  for(int i = 0; i < k; i++){
    c[pd[i]] = false;
  }
  mt19937 rng(36);
  vector<int>p(n);
  iota(p.begin(), p.end(), 0);
  shuffle(p.begin(), p.end(), rng);
  for(int i = 0; i < n && x > 0; i += 2){
    if(!c[p[i]] && !c[p[i + 1]]){
      continue;
    }
    if(x % 3 == 0){
      if(c[p[i]]){
        send[p[i]] = true; 
        x /= 3;
      }
    }
    else if(x % 3 == 1){
      if(c[p[i + 1]]){
        send[p[i + 1]] = true;
        x /= 3;
      }
    }
    else if(c[p[i]] && c[p[i + 1]]){
      send[p[i]] = send[p[i + 1]] = true;
      x /= 3;
    }
  }
  for(int i = 0; i < n; i++){
    Set(i, send[i]);
  }
}
#include "Brunolib.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Bruno(int n, int a[]){
  mt19937 rng(36);
  vector<int>p(n);
  iota(p.begin(), p.end(), 0);
  shuffle(p.begin(), p.end(), rng);
  ll ans = 0;
  for(int i = n - 2; i > -1; i -= 2){
    if(a[p[i]] || a[p[i + 1]]){
      if(a[p[i]] && a[p[i + 1]]){
        ans = ans * 3 + 2;
      }
      else if(a[p[i + 1]]){
        ans = ans * 3 + 1;
      }
      else{
        ans *= 3;
      }
    }
  }
  return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...