제출 #990557

#제출 시각아이디문제언어결과실행 시간메모리
990557jakobrsAncient Machine 2 (JOI23_ancient2)C++17
97 / 100
52 ms904 KiB
#include "ancient2.h"

#include <bitset>
#include <memory>
#include <numeric>
#include <string>
#include <vector>

void gauss(std::bitset<2000> (&matrix)[1000]) {
  for (int col = 0; col < 1000; col++) {
    int pivot_row;
    for (int row = col; row < 1000; row++) {
      if (matrix[row][col]) {
        pivot_row = row;
        break;
      }
    }
    std::swap(matrix[col], matrix[pivot_row]);
    for (int row = col + 1; row < 1000; row++)
      if (matrix[row][col])
        matrix[row] ^= matrix[col];
  }
  for (int col = 999; col >= 0; col--) {
    for (int row = col - 1; row >= 0; row--)
      if (matrix[row][col])
        matrix[row] ^= matrix[col];
  }
}

std::string Solve(int N) {
  int m = 57 * 2;
  std::vector<int> a(m), b(m);
  std::vector<bool> results;
  int acc_phi = 0;

  auto matrix = std::make_unique<std::bitset<2000>[]>(1000);
  for (int i = 1; i < 58; i++) {
    for (int j = 0; j < i; j++) {
      a[j] = j + 1;
      a[j + i] = j + i + 1;
      b[j] = j + 1;
      b[j + i] = j + i + 1;
    }
    a[i - 1] = 0;
    a[i - 1 + i] = i;
    b[i - 1] = 0;
    b[i - 1 + i] = i;

    int phi = 0;
    for (int j = 1; j <= i; j++)
      if (std::gcd(i, j) == 1)
        phi += 1;

    for (int j = 0; j < phi; j++) {
      for (int k = 0; k < 1000; k++) {
        if (k % i == j) {
          matrix[results.size()][k] = 1;
        }
      }
      matrix[results.size()][1000 + results.size()] = 1;

      std::swap(b[j], b[j + i]);
      auto res = Query(m, a, b);
      results.push_back(res >= i);
      std::swap(b[j], b[j + i]);
    }
  }

  gauss(*(std::bitset<2000>(*)[1000])matrix.get());

  std::vector<bool> answer(1000);

  for (int i = 0; i < 1000; i++)
    if (results[i])
      for (int j = 0; j < 1000; j++)
        if (matrix[j][i + 1000])
          answer[j] = !answer[j];

  std::string s;

  for (int i = 0; i < 1000; i++)
    s.push_back(answer[i] ? '1' : '0');

  s.erase(s.begin() + N, s.end());

  return s;
}

컴파일 시 표준 에러 (stderr) 메시지

ancient2.cpp: In function 'std::string Solve(int)':
ancient2.cpp:34:7: warning: unused variable 'acc_phi' [-Wunused-variable]
   34 |   int acc_phi = 0;
      |       ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...