제출 #1025079

#제출 시각아이디문제언어결과실행 시간메모리
1025079TraianDanciuBroken Device (JOI17_broken_device)C++17
100 / 100
30 ms3084 KiB
#include "Annalib.h"
#include <algorithm>
#include <random>

#include <stdio.h>

#define MAXN 150
#define SEED 53702439
#define BAZA 3

void Anna(int n, long long x, int k, int p[]) {
  int i, cif, ok, poz[MAXN];
  std::mt19937 shuffler(SEED);
  char sterg[MAXN];
  
  for(i = 0; i < n; i++) {
    poz[i] = i;
    sterg[i] = 0;
  }
  std::shuffle(poz, poz + n, shuffler);

  for(i = 0; i < k; i++) {
    sterg[p[i]] = 1;
  }

  for(i = 0; i < n / 2; i++) {
    cif = x % BAZA;
    
    // 00 - nu folosim
    // 01 - cifra 0
    // 10 - cifra 1
    // 11 - cifra 2

    ok = 0;
    if(cif == 0 && sterg[poz[2 * i + 1]] == 0) {
      Set(poz[2 * i], 0);
      Set(poz[2 * i + 1], 1);
      ok = 1;
    } else if(cif == 1 && sterg[poz[2 * i]] == 0) {
      Set(poz[2 * i], 1);
      Set(poz[2 * i + 1], 0);
      ok = 1;
    } else if(cif == 2 && sterg[poz[2 * i]] == 0 && sterg[poz[2 * i + 1]] == 0) {
      Set(poz[2 * i], 1);
      Set(poz[2 * i + 1], 1);
      ok = 1;
    }

    if(ok == 0) {
      Set(poz[2 * i], 0);
      Set(poz[2 * i + 1], 0);
    } else {
      x /= BAZA;
    }
  }
}
#include "Brunolib.h"
#include <algorithm>
#include <random>

#define SEED 53702439
#define MAXN 150

long long Bruno(int n, int a[]) {
  int i, poz[MAXN];
  long long p3, x;
  std::mt19937 shuffler(SEED);

  for(i = 0; i < n; i++) {
    poz[i] = i;
  }
  std::shuffle(poz, poz + n, shuffler);

  p3 = 1;
  x = 0;
  for(i = 0; i < MAXN / 2; i++) {
    // 00 - nu folosim
    // 01 - cifra 0
    // 10 - cifra 1
    // 11 - cifra 2

    if(a[poz[2 * i]] == 1) {
      x += p3;
      if(a[poz[2 * i + 1]] == 1) {
        x += p3;
      }
    }

    if(a[poz[2 * i]] || a[poz[2 * i + 1]]) {
      p3 *= 3;
    }
  }

  return x;
}
#Verdict Execution timeMemoryGrader output
Fetching results...