제출 #24099

#제출 시각아이디문제언어결과실행 시간메모리
24099jiaqiyangBroken Device (JOI17_broken_device)C++14
100 / 100
55 ms2836 KiB
#include "Annalib.h"
#include <cstdio>
#include <cstring>

typedef long long i64;

static bool ans[200];

inline void append(int x, bool a, bool b, bool c) {
  ans[x] = a;
  ans[x + 1] = b;
  ans[x + 2] = c;
}

void Anna(int n, i64 x, int k, int p[]) {
  static bool flag[200];
  memset(flag, 0, sizeof flag);
  for (int i = 0; i < k; ++i) flag[p[i]] = true;
  memset(ans, 0, sizeof ans);
  for (int i = 0; i < n; i += 3) {
    int cnt = flag[i] + flag[i + 1] + flag[i + 2];
    if (cnt > 1) continue;
    if (flag[i]) {
      if (x & 1) append(i, 0, 1, 0); else append(i, 0, 0, 1);
      x >>= 1;
    } else if (flag[i + 1]) {
      if (x & 1) append(i, 1, 0, 1); else append(i, 0, 0, 1);
      x >>= 1;
    } else if (flag[i + 2]) {
      if (x & 1) {
        append(i, 0, 1, 0);
        x >>= 1;
      } else if (x & 2) {
        append(i, 1, 0, 0);
        x >>= 2;
      } else {
        append(i, 1, 1, 0);
        x >>= 2;
      }
    } else {
      switch (x & 3) {
        case 0: append(i, 1, 1, 0); break;
        case 1: append(i, 0, 1, 1); break;
        case 2: append(i, 1, 0, 0); break;
        case 3: append(i, 1, 1, 1); break;
      }
      x >>= 2;
    }
  }
  for (int i = 0; i < n; ++i) Set(i, ans[i] && !flag[i]);
}
#include "Brunolib.h"

typedef long long i64;

i64 Bruno(int n, int a[]) {
  i64 res = 0, base = 1;
  for (int i = 0; i < n; i += 3) {
    int cur = a[i] | (a[i + 1] << 1) | (a[i + 2] << 2);
    switch (cur) {
      case 4:
        base <<= 1;
        break;
      case 2:
      case 5:
        res += base;
        base <<= 1;
        break;
      case 3:
        base <<= 2;
        break;
      case 6:
        res += base;
        base <<= 2;
        break;
      case 1:
        res += 2 * base;
        base <<= 2;
        break;
      case 7:
        res += 3 * base;
        base <<= 2;
        break;
    }
  }
  return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...