結果

問題 No.456 Millions of Submits!
ユーザー むらためむらため
提出日時 2017-08-18 07:54:56
言語 Nim
(2.0.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,465 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 57,468 KB
最終ジャッジ日時 2023-09-12 14:51:25
合計ジャッジ時間 2,294 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 41) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
stack trace: (most recent call last)
Main.nim(5, 7)           unpack
/home/judge/data/code/Main.nim(23, 23) template/generic instantiation of `unpack` from here
/home/judge/data/code/Main.nim(5, 7) Error: index 1 not in 0 .. 0

ソースコード

diff #

import sequtils,strutils,algorithm,math,future,macros
template get*():string = stdin.readLine().strip()
macro unpack*(arr: auto,cnt: static[int]): auto =
  let t = genSym(); result = quote do:(let `t` = `arr`;())
  for i in 0..<cnt: result[0][1].add(quote do:`t`[`i`])
template times*(n:int,body) = (for _ in 0..<n: body)

# t , n^a (log n)^b 秒
# 53_300k_1.txt -> 1600 ms (parallel::3003ms... -> 1705ms)
proc printf(formatstr: cstring){.header: "<stdio.h>", varargs.}
proc scanf(formatstr: cstring){.header: "<stdio.h>", varargs.}
proc scan3f():seq[float] =
  var a,b,c : float
  scanf("%lf%lf%lf",addr a,addr b,addr c)
  return @[a,b,c].mapIt(it)
let
  M = get().parseInt()
  ABT = newSeqWith(M,scan3f())
var ans = newSeq[float](M)


proc solve(m:int) =
  let (a,b,t) = ABT[m].unpack(3)
  proc newton(a,b,t:float): float =
    result = 1.1
    var lnx = ln(result)
    for i in 1..25:
      result -= (a*lnx + b*lnx.ln - t.ln) / ((a*lnx + b) / (result*lnx))
      lnx = result.ln
  ans[m] = if a == 0: exp(pow(t, 1.0/b))
        elif b == 0: pow(t, 1.0/a)
        else: newton(a,b,t)

template parallelDo(fn:int->void ,MIN,MAX:int) =
  # do fn(i) parallel :: i in [MIN..<MAX]
  import cpuinfo#,threadpool
  let STEP = max(1,(MAX - MIN) div countProcessors())
  proc solveProc(m:int) = (for mi in m..< min(m+STEP,M): fn(mi))
  for m in countup(MIN,MAX,STEP):
    #spawn
    solveProc(m)
  #sync()

parallelDo(solve,0,M)
for m in 0..<M:
  printf("%.12f\n",ans[m])
0