답안 #990786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990786 2024-05-31T10:48:05 Z jakobrs Ancient Machine 2 (JOI23_ancient2) C++17
99 / 100
37 ms 604 KB
#include "ancient2.h"

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

void gauss(std::bitset<1001> (&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) {
  constexpr int W = 53;
  int m = W * 2;
  std::vector<int> a(m), b(m);
  std::vector<bool> results;
  int acc_phi = 0;

  auto matrix = std::make_unique<std::bitset<1001>[]>(1000);
  auto init_cyclic = [&](int i) -> void {
    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 cur = 0;

  // Periodic vectors
  for (int i = 1; i <= W; i++) {
    init_cyclic(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[cur][k] = 1;
        }
      }

      std::swap(b[j], b[j + i]);
      matrix[cur++][1000] = Query(m, a, b) >= i;
      std::swap(b[j], b[j + i]);
    }
  }

  { // Block 2
    auto if_0 = 2 * W - 2;
    auto if_1 = 2 * W - 1;

    for (int i = 0; i < 2 * W - 2; i++) {
      a[i] = i + 1;
      b[i] = i + 1;
    }
    a[if_0] = if_0;
    b[if_0] = if_0;
    a[if_1] = if_1;
    b[if_1] = if_1;

    for (int i = 0; i < 2 * W - 2; i++) {
      matrix[cur][i] = 1;

      a[i] = if_0;
      b[i] = if_1;
      matrix[cur++][1000] = Query(m, a, b) == if_1;
      a[i] = i + 1;
      b[i] = i + 1;
    }
  }

  // Block 3
  init_cyclic(W);
  for (int pos = 999; cur < 1000; pos--) {
    matrix[cur][pos] = 1;

    auto i = pos % W;
    std::swap(a[W + i], b[i]);
    matrix[cur++][1000] = Query(m, a, b) >= W;
    std::swap(a[W + i], b[i]);
  }

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

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

  return s;
}

Compilation message

ancient2.cpp: In function 'std::string Solve(int)':
ancient2.cpp:34:7: warning: unused variable 'acc_phi' [-Wunused-variable]
   34 |   int acc_phi = 0;
      |       ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 25 ms 344 KB Output is partially correct
2 Partially correct 28 ms 596 KB Output is partially correct
3 Partially correct 24 ms 544 KB Output is partially correct
4 Partially correct 30 ms 592 KB Output is partially correct
5 Partially correct 24 ms 540 KB Output is partially correct
6 Partially correct 23 ms 556 KB Output is partially correct
7 Partially correct 33 ms 344 KB Output is partially correct
8 Partially correct 23 ms 552 KB Output is partially correct
9 Partially correct 25 ms 344 KB Output is partially correct
10 Partially correct 23 ms 596 KB Output is partially correct
11 Partially correct 23 ms 592 KB Output is partially correct
12 Partially correct 26 ms 344 KB Output is partially correct
13 Partially correct 29 ms 544 KB Output is partially correct
14 Partially correct 25 ms 604 KB Output is partially correct
15 Partially correct 24 ms 592 KB Output is partially correct
16 Partially correct 23 ms 344 KB Output is partially correct
17 Partially correct 26 ms 528 KB Output is partially correct
18 Partially correct 26 ms 344 KB Output is partially correct
19 Partially correct 24 ms 344 KB Output is partially correct
20 Partially correct 32 ms 344 KB Output is partially correct
21 Partially correct 24 ms 592 KB Output is partially correct
22 Partially correct 26 ms 344 KB Output is partially correct
23 Partially correct 23 ms 344 KB Output is partially correct
24 Partially correct 25 ms 592 KB Output is partially correct
25 Partially correct 26 ms 592 KB Output is partially correct
26 Partially correct 26 ms 344 KB Output is partially correct
27 Partially correct 23 ms 344 KB Output is partially correct
28 Partially correct 23 ms 528 KB Output is partially correct
29 Partially correct 25 ms 544 KB Output is partially correct
30 Partially correct 23 ms 344 KB Output is partially correct
31 Partially correct 24 ms 344 KB Output is partially correct
32 Partially correct 26 ms 540 KB Output is partially correct
33 Partially correct 25 ms 544 KB Output is partially correct
34 Partially correct 26 ms 344 KB Output is partially correct
35 Partially correct 24 ms 592 KB Output is partially correct
36 Partially correct 23 ms 344 KB Output is partially correct
37 Partially correct 26 ms 528 KB Output is partially correct
38 Partially correct 37 ms 544 KB Output is partially correct
39 Partially correct 24 ms 528 KB Output is partially correct
40 Partially correct 29 ms 344 KB Output is partially correct
41 Partially correct 24 ms 524 KB Output is partially correct
42 Partially correct 23 ms 344 KB Output is partially correct
43 Partially correct 24 ms 592 KB Output is partially correct
44 Partially correct 23 ms 344 KB Output is partially correct
45 Partially correct 27 ms 344 KB Output is partially correct
46 Partially correct 28 ms 592 KB Output is partially correct
47 Partially correct 31 ms 344 KB Output is partially correct
48 Partially correct 24 ms 548 KB Output is partially correct
49 Partially correct 26 ms 344 KB Output is partially correct
50 Partially correct 32 ms 544 KB Output is partially correct
51 Partially correct 23 ms 524 KB Output is partially correct
52 Partially correct 24 ms 592 KB Output is partially correct
53 Partially correct 27 ms 592 KB Output is partially correct
54 Partially correct 27 ms 552 KB Output is partially correct
55 Partially correct 24 ms 344 KB Output is partially correct
56 Partially correct 25 ms 532 KB Output is partially correct
57 Partially correct 25 ms 544 KB Output is partially correct
58 Partially correct 24 ms 528 KB Output is partially correct
59 Partially correct 35 ms 528 KB Output is partially correct
60 Partially correct 32 ms 592 KB Output is partially correct
61 Partially correct 23 ms 344 KB Output is partially correct
62 Partially correct 23 ms 544 KB Output is partially correct
63 Partially correct 25 ms 344 KB Output is partially correct