結果

問題 No.2368 I love a square root of 2
ユーザー 👑 hos.lyrichos.lyric
提出日時 2023-06-30 21:59:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 3,712 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 107,080 KB
実行使用メモリ 10,612 KB
最終ジャッジ日時 2023-09-21 15:58:17
合計ジャッジ時間 3,396 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
4,376 KB
testcase_01 AC 15 ms
4,380 KB
testcase_02 AC 133 ms
10,612 KB
testcase_03 AC 15 ms
4,376 KB
testcase_04 AC 15 ms
4,380 KB
testcase_05 AC 15 ms
4,376 KB
testcase_06 AC 15 ms
4,376 KB
testcase_07 AC 15 ms
4,380 KB
testcase_08 AC 15 ms
4,380 KB
testcase_09 AC 16 ms
4,376 KB
testcase_10 AC 15 ms
4,376 KB
testcase_11 AC 16 ms
4,376 KB
testcase_12 AC 16 ms
4,376 KB
testcase_13 AC 113 ms
10,280 KB
testcase_14 AC 114 ms
9,984 KB
testcase_15 AC 116 ms
9,468 KB
testcase_16 AC 85 ms
9,924 KB
testcase_17 AC 17 ms
4,380 KB
testcase_18 AC 18 ms
4,376 KB
testcase_19 AC 18 ms
4,376 KB
testcase_20 AC 18 ms
4,376 KB
testcase_21 AC 136 ms
9,732 KB
testcase_22 AC 132 ms
10,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

// using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }

#ifndef LIBRA_OTHER_INT128_H_
#define LIBRA_OTHER_INT128_H_

#include <stdio.h>
#include <iostream>

constexpr unsigned __int128 toUInt128(const char *s) {
  unsigned __int128 x = 0;
  for (; *s; ++s) x = x * 10 + (*s - '0');
  return x;
}
constexpr __int128 toInt128(const char *s) {
  if (*s == '-') return -toInt128(s + 1);
  __int128 x = 0;
  for (; *s; ++s) x = x * 10 + (*s - '0');
  return x;
}
unsigned __int128 inUInt128() {
  static char buf[41];
  scanf("%s", buf);
  return toUInt128(buf);
}
__int128 inInt128() {
  static char buf[41];
  scanf("%s", buf);
  return toInt128(buf);
}

void out(unsigned __int128 x) {
  static char buf[41];
  int len = 0;
  do { buf[len++] = '0' + static_cast<int>(x % 10); } while (x /= 10);
  for (int i = len; --i >= 0; ) putchar(buf[i]);
}
void out(__int128 x) {
  if (x < 0) {
    putchar('-');
    out(-static_cast<unsigned __int128>(x));
  } else {
    out(static_cast<unsigned __int128>(x));
  }
}
std::ostream &operator<<(std::ostream &os, unsigned __int128 x) {
  static char buf[41];
  int len = 0;
  do { buf[len++] = '0' + static_cast<int>(x % 10); } while (x /= 10);
  for (int i = len; --i >= 0; ) os << buf[i];
  return os;
}
std::ostream &operator<<(std::ostream &os, __int128 x) {
  if (x < 0) {
    os << '-' << -static_cast<unsigned __int128>(x);
  } else {
    os << static_cast<unsigned __int128>(x);
  }
  return os;
}

#endif  // LIBRA_OTHER_INT128_H_


using Int = __int128;

// https://oeis.org/A155046
constexpr Int P = toInt128("233806732499933208099");
constexpr Int Q = toInt128("165326326037771920630");

// #{ (a, b) | a + sqrt(2) b <= t }
Int solve(Int t) {
  Int ret = 0;
  for (Int b = 0; ; ++b) {
    const Int limA = t - b * P / Q;
    if (limA < 0) break;
    ret += (limA + 1);
  }
  return ret;
}

int main() {
  long long N_;
  for (; ~scanf("%lld", &N_); ) {
    const Int N = N_;
    
    Int lo = -1, hi = 200'000;
    assert(solve(hi) >= N);
    for (; lo + 1 < hi; ) {
      const Int mid = (lo + hi) / 2;
      ((solve(mid) < N) ? lo : hi) = mid;
    }
    const Int resLo = solve(lo);
// cerr<<"lo = "<<lo<<", solve(lo) = "<<resLo<<endl;
    
    vector<pair<Int, pair<Int, Int>>> ps;
    for (Int b = 0; ; ++b) {
      const Int a = hi - b * P / Q;
      if (a < 0) break;
      ps.emplace_back(Q * a + P * b, make_pair(a, b));
    }
    sort(ps.begin(), ps.end());
// cerr<<"ps = "<<ps<<endl;
    const auto ans = ps[N - resLo - 1].second;
    
    out(ans.first);
    putchar(' ');
    out(ans.second);
    puts("");
  }
  return 0;
}
0