結果

問題 No.456 Millions of Submits!
ユーザー rsk0315rsk0315
提出日時 2018-03-09 05:15:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,542 ms / 4,500 ms
コード長 4,286 bytes
コンパイル時間 1,097 ms
コンパイル使用メモリ 64,968 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 18:13:26
合計ジャッジ時間 6,801 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 17 ms
5,376 KB
testcase_10 AC 17 ms
5,376 KB
testcase_11 AC 155 ms
5,376 KB
testcase_12 AC 1,542 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:197:5: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
  197 |     if (b == 0) {
      |     ^~
main.cpp:193:12: note: 'b' was declared here
  193 |     int a, b;
      |            ^

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <cstdint>
#include <cstdlib>
#include <cstddef>
#include <cinttypes>
#include <cfenv>
#include <cmath>

#include <type_traits>
#include <limits>
#include <algorithm>

namespace FastIn {
  static constexpr size_t BUF_SIZE=1<<17, INT_LEN=24, FLT_LEN=400;
  static char buf[BUF_SIZE|1]={}, *pos=buf, *endbuf=nullptr;
  FILE *fin;

  inline bool rebuffer() {
    // returns true <=> there is at least one unread character
    size_t rest=endbuf-pos;
    if (buf+rest > pos) {
      // buf[:pos] and buf[-pos:] are overlapping, which std::memcpy()
      // causes undefined behavior.
      return true;
    }

    std::memcpy(buf, pos, rest); 
    pos = buf;
    size_t len=std::fread(pos+rest, 1, BUF_SIZE-rest, fin);
    *(endbuf = buf + (rest+len)) = 0;

    return *pos;
  }

  inline bool scan(char &in) {
    if ((in = *pos)) {
      ++pos;
      return true;
    }

    return rebuffer() && (in = *pos++);
  }

  inline bool scan(char *in) {
    if ((*in = *pos) == 0) {
      if (rebuffer() && (*in = *pos) == 0) {
        return false;
      }
    }
    ++in;
    while (true) {
      if ((*in = *pos++) == 0) {
        if (rebuffer() && (*in = *pos++) == 0) {
          return true;
        }
      }
      ++in;
    }
  }

  inline bool scan(double &in) {
    if (pos + FLT_LEN >= endbuf && !rebuffer()) {
      in = 0.0;
      return false;
    }

#if 0
    char *tmp;
    in = std::strtod(pos, &tmp);
    pos = ++tmp;
    return true;
#else
    intmax_t intpart=0;
    bool is_neg=false;
    if (*pos == '-') {
      ++pos;
      is_neg = true;
    }
    while (*pos >= '0') {
      intpart = intpart*10 + *pos-'0';
      ++pos;
    }
    if (*pos++ != '.') {
      in = (is_neg? -intpart:intpart);
      return true;
    }
    intmax_t fracpart=0;
    const char *startp=pos;
    while (*pos >= '0') {
      fracpart = fracpart*10 + *pos-'0';
      ++pos;
    }
    constexpr double tenths[20]={
      1,     0.1,   0.01,  1e-3,  1e-4,  1e-5,  1e-6,  1e-7,  1e-8,  1e-9,
      1e-10, 1e-11, 1e-12, 1e-13, 1e-14, 1e-15, 1e-16, 1e-17, 1e-18, 1e-19,
    };
    in = intpart + fracpart*tenths[pos-startp];
    if (is_neg) in = -in;
    ++pos;
#endif
    return true;
  }

  template <class Int>
  inline bool scan(Int &in) {
    in = 0;

    // assume that no redundant whitespace appears
    if (pos + INT_LEN >= endbuf && !rebuffer()) {
      return false;
    }

    if (std::is_signed<Int>::value) {
      if (*pos == '-') {
        in = ~*++pos+'1';
        while (*++pos >= '0') {
          in = in*10 + ~*pos+'1';
        }
        ++pos;
        return true;
      }
    }

    // assume that numbers are separated by the character whose value is
    // less than '0' (e.g. whitespaces, newlines)
    do {
      in = in*10 + *pos-'0';
    } while (*++pos >= '0');
    ++pos;
    return true;
  }

  inline bool eat() {
    if (*pos > ' ') {
      return true;
    }

    do {
      if (*pos == 0 && !rebuffer()) {
        return false;
      }
    } while (*++pos <= ' ');

    return true;
  }

  inline bool eat(char ch) {
    if (*pos == ch) {
      return true;
    }

    do {
      if (*pos == 0 && !rebuffer()) {
        return false;
      }
    } while (*++pos != ch);

    return true;
  }

  class Scanner {
    bool rebuffer() {
      return FastIn::rebuffer();
    }

  public:
    Scanner(FILE *fin=stdin) {
      FastIn::fin = fin;
      endbuf = pos + std::fread(buf, 1, BUF_SIZE, fin);
    }

    template <class T>
    inline bool scan(T &in) {
      return FastIn::scan(in);
    }

    template <class First, class... Rest>
    inline bool scan(First &in, Rest &...ins) {
      return scan(in) && scan(ins...);
    }
  };
}

FastIn::Scanner cin;

int main() {
  int m;
  cin.scan(m);

  constexpr double e=exp(1);
  for (int i=0; i<m; ++i) {
    int a, b;
    double t;
    cin.scan(a, b, t);

    if (b == 0) {
      printf("%.12f\n", pow(t, 1.0/a));
      continue;
    }
    if (a == 0) {
      printf("%.12f\n", exp(pow(t, 1.0/b)));
      continue;
    }
    double q=pow(t, 1.0/b)*a/b;
    double lb=std::min(e, q), ub=std::max(e, q);
    for (int i=0; i<50; ++i) {
      double mid=(lb+ub)/2.0;
      (mid*log(mid)<q? lb:ub) = mid;
    }
    printf("%.12f\n", pow(ub, static_cast<double>(b)/a));
  }
}
0