답안 #572607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572607 2022-06-04T19:51:07 Z Plurm 순열 (APIO22_perm) C++17
91.3333 / 100
4 ms 340 KB
#include "perm.h"
#include <algorithm>

class intperm {
public:
  std::vector<int> perm;
  long long value;
  intperm(std::vector<int> perm = {}, long long value = 1)
      : perm(perm), value(value) {}
  std::pair<int, int> get_bounds() {
    return std::make_pair(*min_element(perm.begin(), perm.end()),
                          *max_element(perm.begin(), perm.end()));
  }
  friend bool operator<(const intperm &a, const intperm &b) {
    return a.value < b.value;
  }
  friend intperm operator+(intperm a, intperm b) {
    intperm nxt;
    if (b < a) {
      std::swap(a.perm, b.perm);
      std::swap(a.value, b.value);
    }
    nxt.perm = b.perm;
    int offs = (a.perm.empty() ? 0 : a.get_bounds().second + 1);
    for (int &x : nxt.perm)
      x += offs;
    nxt.perm.insert(nxt.perm.end(), a.perm.begin(), a.perm.end());
    nxt.value = a.value + b.value - 1;
    return nxt;
  }
  friend intperm operator*(intperm a, intperm b) {
    intperm nxt;
    if (b < a) {
      std::swap(a.perm, b.perm);
      std::swap(a.value, b.value);
    }
    nxt.perm = b.perm;
    int offs = (a.perm.empty() ? 0 : a.get_bounds().second + 1);
    for (int &x : nxt.perm)
      x += offs;
    nxt.perm.insert(nxt.perm.begin(), a.perm.begin(), a.perm.end());
    nxt.value = a.value * b.value;
    return nxt;
  }
};

const intperm ONE({}, 1);
const intperm TWO({0}, 2);
std::vector<int> construct_permutation(long long k) {
  intperm ans;
  int msb = 63 - __builtin_clzll(k);
  for (long long i = msb - 1; i >= 0; i--) {
    ans = ans * TWO;
    if (k & (1ll << i)) {
      ans = ans + TWO;
    }
  }
  return ans.perm;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Partially correct 2 ms 284 KB Partially correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 308 KB Output is correct
8 Partially correct 2 ms 340 KB Partially correct
9 Correct 2 ms 340 KB Output is correct
10 Partially correct 3 ms 288 KB Partially correct
11 Partially correct 4 ms 340 KB Partially correct
12 Partially correct 3 ms 340 KB Partially correct
13 Partially correct 3 ms 292 KB Partially correct