結果

問題 No.691 E869120 and Constructing Array 5
ユーザー Min_25Min_25
提出日時 2018-05-19 00:09:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,821 bytes
コンパイル時間 920 ms
コンパイル使用メモリ 94,956 KB
実行使用メモリ 275,016 KB
最終ジャッジ日時 2023-09-11 00:12:34
合計ジャッジ時間 5,721 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 667 ms
135,912 KB
testcase_02 AC 680 ms
136,372 KB
testcase_03 AC 678 ms
134,716 KB
testcase_04 AC 681 ms
135,348 KB
testcase_05 AC 679 ms
136,252 KB
testcase_06 AC 678 ms
135,996 KB
testcase_07 AC 678 ms
134,576 KB
testcase_08 AC 680 ms
135,256 KB
testcase_09 AC 679 ms
136,376 KB
testcase_10 AC 682 ms
135,128 KB
testcase_11 AC 677 ms
136,056 KB
testcase_12 AC 687 ms
134,576 KB
testcase_13 AC 681 ms
135,292 KB
testcase_14 AC 686 ms
136,176 KB
testcase_15 AC 675 ms
135,724 KB
testcase_16 AC 680 ms
135,292 KB
testcase_17 AC 683 ms
135,080 KB
testcase_18 AC 679 ms
135,576 KB
testcase_19 AC 690 ms
134,604 KB
testcase_20 AC 685 ms
135,864 KB
testcase_21 AC 685 ms
135,636 KB
testcase_22 AC 692 ms
135,868 KB
testcase_23 AC 705 ms
135,252 KB
testcase_24 AC 679 ms
135,768 KB
testcase_25 AC 681 ms
134,932 KB
testcase_26 AC 677 ms
134,760 KB
testcase_27 AC 631 ms
275,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstring>

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <stack>
#include <queue>

#include <tuple>

#define getchar getchar_unlocked
#define putchar putchar_unlocked

#define _rep(_1, _2, _3, _4, name, ...) name
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c))
#define rep(...) _rep(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__)

using namespace std;

using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f80 = long double;

int get_int() {
  int c, n;
  while ((c = getchar()) < '0');
  n = c - '0';
  while ((c = getchar()) >= '0') n = n * 10 + (c - '0');
  return n;
}

f80 fractional_part(int N) {
  f80 v = sqrtl(N);
  int iv = v;
  i64 numer = N - iv * iv;
  return numer / (v + iv);
}

void solve() {
  const int base = 1234567;
  const int K = 2400;
  vector<int> ns(K); rep(i, K) ns[i] = rand() % base;
  vector< pair<f80, int> > values;
  vector<f80> fs;
  rep(i, K) fs.push_back(fractional_part(ns[i]));
  rep(i, K) rep(j, i, K) {
    f80 a = fs[i] + fs[j]; if (a >= 1) a -= 1;
    values.emplace_back(a, i + j * K);
  }
  sort(values.begin(), values.end());

  int Q; scanf("%d", &Q);
  rep(i, Q) {
    f80 f; scanf("%Lf", &f);
    f80 target = f - (i64) f;;
    int tail = lower_bound(
      values.begin(), values.end(), make_pair(target, 100000000)) - values.begin();
    if (tail == (int) values.size()) --tail;
    int head = 0;
    f80 best = 1e-6;
    i64 mask = 0;
    while (head < (int) values.size() && tail >= 0) {
      f80 s = values[head].first + values[tail].first;
      if (s < target) {
        if (target - s < best) {
          best = target - s;
          mask = values[head].second + i64(values[tail].second) * K * K;
        }
        head++;
      } else {
        if (s - target < best) {
          best = s - target;
          mask = values[head].second + i64(values[tail].second) * K * K;
        }
        --tail;
      }
      if (best < 1e-10) break;
    }
    // fprintf(stderr, "%.16Lf\n", best);
    // fprintf(stderr, "%.16Lf\n", t);
    // fprintf(stderr, "%.16Lf\n", f);
    assert(best < 1e-10);
    f80 t = 0;
    printf("%d", 5);
    rep(_, 4) {
      int j = mask % K; mask /= K;
      t += sqrtl(ns[j]);
      printf(" %d", ns[j]);
    }
    int integer_part = (int) round(f - t);
    t += integer_part;
    assert(integer_part >= 0);
    printf(" %d\n", integer_part * integer_part);
    assert((f - t) < 1e-9);

  }
}

int main() {
  clock_t beg = clock();
  solve();
  clock_t end = clock();
  fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC);
  return 0;
}
0