답안 #1034356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034356 2024-07-25T12:35:41 Z vjudge1 비교 (balkan11_cmp) C++17
0 / 100
471 ms 82924 KB
#include "cmp.h"
#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()

const int N = 4096;

mt19937 rng(time(nullptr) + 69);

bool f = 1;
int cnt[2][12][N];

void remember(int a) {
  if (f) {
    f = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 12; j++) {
        cnt[0][j][i] = cnt[1][j][i] = 2048;
      }
    }
  }

  int x = __builtin_popcount(a);
  if (x <= 1 + 12-x) {
    for (int i = 0; i <= 11; i++) {
      if ((a >> i) & 1) bit_set(i+1);
    }
  }
  else {
    bit_set(13);
    for (int i = 0; i <= 11; i++) {
      if (!((a >> i) & 1)) bit_set(i+1);
    }
  }
}

int compare(int b) {
  vector<int> bt(12);
  for (int i = 0; i < 12; i++) {
    bt[i] = i;
  }
  shuffle(all(bt), rng);

  int inv = -1;

  int mask = 0;
  int yes = 0;
  int no = 0;
  for (int i = 0; i < 12; i++) {
    // bt[i]

    // de los que me quedan, todos tienen el mismo bit en esta posicion?

    bool on = (cnt[2][bt[i]][b] > 0 ? 1 : 0);
    bool off = (cnt[1][bt[i]][b] > 0 ? 1 : 0);

    int x;

    if (!on) {
      x = 0;
    }
    else if (!off) {
      x = 1;
    }
    else {
      x = bit_get(bt[i]+1);
      if (inv == -1) inv = bit_get(13);
      if (inv) x = !x;
    }

    if (x) {
      mask ^= (1 << bt[i]);
      yes++;
    }
    else {
      no++;
    }

    if (inv) {
      // tiene >= 7 bits activados
      if (no == 5) {
        for (int j = i+1; j < 12; j++) {
          mask ^= (1 << bt[j]);
        }
        break;
      }
    }
    else {
      // tiene <= 6 bits activados
      if (yes == 6) break;
    }
  }

  for (int i = 0; i < 12; i++) {
    if ((mask >> i) & 1) cnt[1][i][b]--;
    else cnt[0][i][b]--;
  }

  if (mask > b) return -1;
  else if (mask == b) return 0;
  else return 1;
}

Compilation message

cmp.cpp: In function 'int compare(int)':
cmp.cpp:55:21: warning: array subscript 2 is above array bounds of 'int [2][12][4096]' [-Warray-bounds]
   55 |     bool on = (cnt[2][bt[i]][b] > 0 ? 1 : 0);
      |                ~~~~~^
cmp.cpp:12:5: note: while referencing 'cnt'
   12 | int cnt[2][12][N];
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 471 ms 82924 KB ZERO POINTS: For a=479 and b=1004, correct answer is 1, got -1