답안 #1089506

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089506 2024-09-16T15:34:41 Z vjudge1 Xor Sort (eJOI20_xorsort) C++17
0 / 100
1000 ms 344 KB
/* https://oj.uz/problem/view/eJOI20_xorsort?locale=en: WA */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

unsigned int N, S, A[1000];
std::vector<std::pair<unsigned int, unsigned int>> operations;

void lazerpisssort(unsigned int i, unsigned int j) {
  unsigned int split, k, mask;

  if (i == j)
    return;
  for (k = i; k < j-1; ++k)
    if (A[k] > A[k+1])
      goto actually_sort;
  return;
actually_sort:
  for (mask = 0, k = i; k < j; ++k)
    mask |= A[k];
  while (mask & (mask - 1))
    mask &= mask - 1;
  for (k = i; k < j - 1; ++k)
    if ((mask & A[k]) && !(mask & A[k+1])) {
      A[k+1] ^= A[k];
      operations.push_back({k+1, k});
    }
  for (split = i; split < j; ++split)
    if (mask & A[split])
      break;
  lazerpisssort(i, split);
  lazerpisssort(split, j);
}

void cursedbubblesort(unsigned int j) {
  unsigned int i, k;

  if (j == 1)
    return;
  k = 0;
  for (i = 1; i < j; ++i)
    if (A[i] > A[k])
      k = i;
  if (j == k)
    return;
  for (i = k; i < j - 1; ++i)
    operations.push_back({i+1, i});
  for (i = 0; i < j - 1; ++i)
    operations.push_back({i, i+1});
  memmove(&A[k], &A[k+1], sizeof(*A)*(j-k-1));
  cursedbubblesort(j - 1);
}

int main(void) {
  (void) scanf("%u %u", &N, &S);
  for (unsigned int i = 0; i < N; ++i)
    (void) scanf(" %u", &A[i]);
  if (S == 1) {
    for (unsigned int i = 0; i < N - 1; ++i)
      operations.push_back({i, i+1});
    cursedbubblesort(N);
  } else {
    lazerpisssort(0, N);
  }
  printf("%u\n", operations.size());
  for (auto operation : operations)
    printf("%u %u\n", operation.first + 1, operation.second + 1);
  return EXIT_SUCCESS;
}

Compilation message

xorsort.cpp: In function 'int main()':
xorsort.cpp:67:12: warning: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'std::vector<std::pair<unsigned int, unsigned int> >::size_type' {aka 'long unsigned int'} [-Wformat=]
   67 |   printf("%u\n", operations.size());
      |           ~^     ~~~~~~~~~~~~~~~~~
      |            |                    |
      |            unsigned int         std::vector<std::pair<unsigned int, unsigned int> >::size_type {aka long unsigned int}
      |           %lu
xorsort.cpp:57:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   (void) scanf("%u %u", &N, &S);
      |          ~~~~~^~~~~~~~~~~~~~~~~
xorsort.cpp:59:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     (void) scanf(" %u", &A[i]);
      |            ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Not sorted
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Not sorted
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1031 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -