結果

問題 No.691 E869120 and Constructing Array 5
ユーザー Min_25Min_25
提出日時 2018-05-19 13:53:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 250 ms / 1,000 ms
コード長 3,255 bytes
コンパイル時間 1,060 ms
コンパイル使用メモリ 94,616 KB
実行使用メモリ 21,072 KB
最終ジャッジ日時 2023-09-11 00:12:44
合計ジャッジ時間 9,689 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 240 ms
19,800 KB
testcase_01 AC 234 ms
19,904 KB
testcase_02 AC 242 ms
20,844 KB
testcase_03 AC 243 ms
20,708 KB
testcase_04 AC 241 ms
20,420 KB
testcase_05 AC 247 ms
20,896 KB
testcase_06 AC 244 ms
20,368 KB
testcase_07 AC 245 ms
19,708 KB
testcase_08 AC 245 ms
19,348 KB
testcase_09 AC 245 ms
19,792 KB
testcase_10 AC 245 ms
19,616 KB
testcase_11 AC 245 ms
19,444 KB
testcase_12 AC 245 ms
20,752 KB
testcase_13 AC 247 ms
21,072 KB
testcase_14 AC 243 ms
20,200 KB
testcase_15 AC 245 ms
19,600 KB
testcase_16 AC 245 ms
19,796 KB
testcase_17 AC 247 ms
20,156 KB
testcase_18 AC 244 ms
19,892 KB
testcase_19 AC 242 ms
19,696 KB
testcase_20 AC 247 ms
21,068 KB
testcase_21 AC 244 ms
19,532 KB
testcase_22 AC 246 ms
19,780 KB
testcase_23 AC 245 ms
19,452 KB
testcase_24 AC 249 ms
20,028 KB
testcase_25 AC 240 ms
19,916 KB
testcase_26 AC 250 ms
20,080 KB
testcase_27 AC 81 ms
20,032 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;
}

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

void solve() {
  const int base = 1234567;
  const int K = 1111;
  vector<int> ns(K); rep(i, K) ns[i] = rand() % base;
  vector< pair<double, int> > values;
  vector<double> fs;
  rep(i, K) fs.push_back(fractional_part(ns[i]));
  rep(i, K) rep(j, i, K) {
    double 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);
    double target = f - (i64) f;

    bool found = false;
    rep(o, 2) {
      int head = 0, tail = 0;
      if (o == 0) {
        tail = lower_bound(
          values.begin(), values.end(), make_pair(target, 100000000)
        ) - values.begin();
        if (tail == (int) values.size()) --tail;
        head = 0;
      } else {
        tail = values.size() - 1;
        head = lower_bound(
          values.begin(), values.end(), make_pair(target, 0)
        ) - values.begin();
        if (head == (int) values.size()) --head;
        target += 1;
      }
      double best = 1e-9;
      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;
            if (best < 0.95e-10) break;
          }
          head++;
        } else {
          if (s - target < best) {
            best = s - target;
            mask = values[head].second + i64(values[tail].second) * K * K;
            if (best < 0.95e-10) break;
          }
          --tail;
        }
      }
      if (best >= 0.95e-10) continue;
      found = true;
      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(abs(f - t) < 1e-10);
      break;
    }
    assert(found);
  }
}

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