Submission #1262071

#TimeUsernameProblemLanguageResultExecution timeMemory
1262071M_W_13Broken Device (JOI17_broken_device)C++20
85 / 100
41 ms1500 KiB
#include "Annalib.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define st first
#define nd second
#define pb push_back

void Anna(int N, long long X, int K, int P[] ){
  vector<int> pom = {101, 64, 129, 87, 86, 38, 57, 92, 137, 89, 69, 29, 99, 44, 26, 78, 40, 32, 23, 37, 21, 73, 80, 48, 35, 33, 118, 96, 121, 71, 134, 62, 126, 12, 5, 72, 9, 51, 95, 132, 100, 123, 45, 59, 39, 22, 53, 41, 66, 140, 43, 90, 124, 27, 14, 112, 68, 56, 131, 114, 67, 116, 144, 97, 127, 109, 74, 24, 133, 46, 25, 60, 50, 148, 54, 11, 42, 94, 16, 105, 36, 77, 98, 58, 3, 108, 103, 7, 117, 93, 18, 125, 113, 84, 63, 75, 130, 4, 143, 104, 102, 88, 8, 31, 10, 145, 147, 19, 30, 141, 139, 82, 13, 149, 106, 122, 85, 120, 2, 55, 61, 135, 1, 20, 142, 119, 47, 110, 91, 146, 49, 76, 79, 0, 138, 52, 34, 128, 107, 83, 15, 111, 28, 136, 6, 70, 81, 115, 17, 65};
  queue<ll> vec;
  rep(i, 38) {
    vec.push(X % 3ll);
    X /= 3ll;
  }
  int pol = N/2;
  bool czy[N];
  rep(i, N) {
    czy[i] = true;
  }
  rep(i, K) {
    int x = P[i];
    czy[x] = false;
  }
  for (int i = 0; i < N; i += 2) {
    int a = pom[i];
    int b = pom[i + 1];
    if (czy[a] && czy[b]) {
      if (vec.empty()) {
        Set(a, 0);
        Set(b, 0);
      }
      else {
        ll p = vec.front();
        vec.pop();
        if (p == 0) {
          Set(a, 0);
          Set(b, 1);
        }
        else if (p == 1) {
          Set(a, 1);
          Set(b, 0);
        }
        else {
          Set(a, 1);
          Set(b, 1);
        }
      }
    }
    else {
      Set(a, 0);
      Set(b, 0);
    }
  }
}
#include "Brunolib.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define st first
#define nd second
#define pb push_back

long long Bruno( int N, int A[] ){
  vector<int> pom = {101, 64, 129, 87, 86, 38, 57, 92, 137, 89, 69, 29, 99, 44, 26, 78, 40, 32, 23, 37, 21, 73, 80, 48, 35, 33, 118, 96, 121, 71, 134, 62, 126, 12, 5, 72, 9, 51, 95, 132, 100, 123, 45, 59, 39, 22, 53, 41, 66, 140, 43, 90, 124, 27, 14, 112, 68, 56, 131, 114, 67, 116, 144, 97, 127, 109, 74, 24, 133, 46, 25, 60, 50, 148, 54, 11, 42, 94, 16, 105, 36, 77, 98, 58, 3, 108, 103, 7, 117, 93, 18, 125, 113, 84, 63, 75, 130, 4, 143, 104, 102, 88, 8, 31, 10, 145, 147, 19, 30, 141, 139, 82, 13, 149, 106, 122, 85, 120, 2, 55, 61, 135, 1, 20, 142, 119, 47, 110, 91, 146, 49, 76, 79, 0, 138, 52, 34, 128, 107, 83, 15, 111, 28, 136, 6, 70, 81, 115, 17, 65};
  ll x = 0;
  ll pot = 1;
  for (int i = 0; i < N; i += 2) {
    int a = pom[i];
    int b = pom[i + 1];
    if (A[a] == 1 && A[b] == 0) {
      x += pot;
    }
    else if (A[a] == 1 && A[b] == 1) {
      x += (2ll * pot);
    }
    if (A[a] == 0 && A[b] == 0) {
      continue;
    }
    pot *= 3ll;
  }
  // cout << "x = " << x << '\n';
  return x;
}
#Verdict Execution timeMemoryGrader output
Fetching results...