結果

問題 No.2262 Fractions
ユーザー risujirohrisujiroh
提出日時 2023-04-07 23:21:54
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,486 bytes
コンパイル時間 2,988 ms
コンパイル使用メモリ 278,628 KB
実行使用メモリ 29,376 KB
最終ジャッジ日時 2024-04-10 18:08:22
合計ジャッジ時間 9,462 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define show(...) static_cast<void>(0)
#define all(c) begin(c), end(c)
#define for(...) for ([[maybe_unused]] auto&& __VA_ARGS__)
#define lambda(...) [&](auto&&... args) { return __VA_ARGS__; }
#define $1 get<0>(tie(args...))
#define $2 get<1>(tie(args...))
template <bool = false> struct Rep {
  int l, r, d;
  Rep begin() const;
  int end() const;
  bool operator!=(int) const;
  void operator++();
  int operator*() const;
};
Rep<> rep(int, int, int = 1);
Rep<> rep1(int, int, int = 1);
Rep<true> per(int, int, int = 1);
Rep<true> per1(int, int, int = 1);
template <class R> int len(R&&);
template <class R, class I> int len(R&&, I);
template <class T, class U = T> bool chmin(T&, U&&);
template <class T, class U = T> bool chmax(T&, U&&);
template <class T> ostream& operator<<(ostream&, const vector<T>&);
template <class T> auto operator<<(ostream& os, T&& t) -> decltype(tuple_cat(t), os);
template <class T = int> T input();
template <class... Ts> void print(Ts&&...);

void solve() {
  int n = input();
  auto k = input<int64_t>();
  int i = 0;
  bool found = false;
  auto dfs = [&](auto self, int a1, int b1, int a2, int b2) -> void {
    int am = a1 + a2;
    int bm = b1 + b2;
    if (n < am || n < bm) {
      return;
    }
    show(am, bm);
    self(self, a1, b1, am, bm);
    ++i;
    if (i == k) {
      found = true;
      cout << am << '/' << bm << '\n';
      return;
    }
    self(self, am, bm, a2, b2);
  };
  dfs(dfs, 0, 1, 1, 0);
  if (!found) {
    print(-1);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  for (_ : rep(0, input())) {
    solve();
  }
}

template <bool R>
Rep<R> Rep<R>::begin() const {
  return *this;
}

template <bool R>
int Rep<R>::end() const {
  return 0;
}

template <bool R>
bool Rep<R>::operator!=(int) const {
  return l <= r;
}

template <bool R>
void Rep<R>::operator++() {
  if constexpr (R) {
    r -= d;
  } else {
    l += d;
  }
}

template <bool R>
int Rep<R>::operator*() const {
  if constexpr (R) {
    return r;
  } else {
    return l;
  }
}

inline Rep<> rep(int l, int r, int d) {
  assert(0 < d);
  return {l, r - 1, d};
}

inline Rep<> rep1(int l, int r, int d) {
  assert(0 < d);
  return {l, r, d};
}

inline Rep<true> per(int l, int r, int d) {
  assert(0 < d);
  assert((r - l) % d == 0);
  return {l, r - d, d};
}

inline Rep<true> per1(int l, int r, int d) {
  assert(0 < d);
  return {l, r, d};
}

template <class R>
int len(R&& r) {
  return static_cast<int>(size(forward<R>(r)));
}

template <class R, class I>
int len(R&& r, I i) {
  return static_cast<int>(distance(begin(forward<R>(r)), i));
}

template <class T, class U>
bool chmin(T& x, U&& y) {
  return y < x && (x = forward<U>(y), true);
}

template <class T, class U>
bool chmax(T& x, U&& y) {
  return x < y && (x = forward<U>(y), true);
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  auto sep = "";
  for (e : v) {
    os << exchange(sep, " ") << e;
  }
  return os;
}

template <class T>
auto operator<<(ostream& os, T&& t) -> decltype(tuple_cat(t), os) {
  auto f = [&](auto&&... args) -> ostream& {
    [[maybe_unused]] auto sep = "";
    (..., (os << exchange(sep, " ") << forward<decltype(args)>(args)));
    return os;
  };
  return apply(f, forward<T>(t));
}

template <class T>
T input() {
  T x;
  cin >> x;
  return x;
}

template <class... Ts>
void print(Ts&&... xs) {
  cout << forward_as_tuple(forward<Ts>(xs)...) << '\n';
}
0