結果
問題 | No.2855 Move on Grid |
ユーザー | kemuniku |
提出日時 | 2024-08-25 14:04:29 |
言語 | Nim (2.0.2) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,134 bytes |
コンパイル時間 | 3,099 ms |
コンパイル使用メモリ | 77,716 KB |
実行使用メモリ | 18,104 KB |
最終ジャッジ日時 | 2024-08-25 14:04:43 |
合計ジャッジ時間 | 11,785 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
ソースコード
import macros;macro ImportExpand(s:untyped):untyped = parseStmt($s[2]) ImportExpand "cplib/tmpl/sheep.nim" <=== "when not declared CPLIB_TMPL_SHEEP:\n const CPLIB_TMPL_SHEEP* = 1\n {.warning[UnusedImport]: off.}\n {.hint[XDeclaredButNotUsed]: off.}\n import algorithm\n import sequtils\n import tables\n import macros\n import math\n import sets\n import strutils\n import strformat\n import sugar\n import heapqueue\n import streams\n import deques\n import bitops\n import std/lenientops\n import options\n #入力系\n proc scanf(formatstr: cstring){.header: \"<stdio.h>\", varargs.}\n proc getchar(): char {.importc: \"getchar_unlocked\", header: \"<stdio.h>\", discardable.}\n proc ii(): int {.inline.} = scanf(\"%lld\\n\", addr result)\n proc lii(N: int): seq[int] {.inline.} = newSeqWith(N, ii())\n proc si(): string {.inline.} =\n result = \"\"\n var c: char\n while true:\n c = getchar()\n if c == ' ' or c == '\\n':\n break\n result &= c\n #chmin,chmax\n template `max=`(x, y) = x = max(x, y)\n template `min=`(x, y) = x = min(x, y)\n #bit演算\n proc `%`*(x: int, y: int): int =\n result = x mod y\n if y > 0 and result < 0: result += y\n if y < 0 and result > 0: result += y\n proc `//`*(x: int, y: int): int{.inline.} =\n result = x div y\n if y > 0 and result * y > x: result -= 1\n if y < 0 and result * y < x: result -= 1\n proc `%=`(x: var int, y: int): void = x = x%y\n proc `//=`(x: var int, y: int): void = x = x//y\n proc `**`(x: int, y: int): int = x^y\n proc `**=`(x: var int, y: int): void = x = x^y\n proc `^`(x: int, y: int): int = x xor y\n proc `|`(x: int, y: int): int = x or y\n proc `&`(x: int, y: int): int = x and y\n proc `>>`(x: int, y: int): int = x shr y\n proc `<<`(x: int, y: int): int = x shl y\n proc `~`(x: int): int = not x\n proc `^=`(x: var int, y: int): void = x = x ^ y\n proc `&=`(x: var int, y: int): void = x = x & y\n proc `|=`(x: var int, y: int): void = x = x | y\n proc `>>=`(x: var int, y: int): void = x = x >> y\n proc `<<=`(x: var int, y: int): void = x = x << y\n proc `[]`(x: int, n: int): bool = (x and (1 shl n)) != 0\n #便利な変換\n proc `!`(x: char, a = '0'): int = int(x)-int(a)\n #定数\n #[ include cplib/utils/constants ]#\n when not declared CPLIB_UTILS_CONSTANTS:\n const CPLIB_UTILS_CONSTANTS* = 1\n const INF32*: int32 = 100100111.int32\n const INF64*: int = int(3300300300300300491)\n const INF = INF64\n #converter\n\n #range\n iterator range(start: int, ends: int, step: int): int =\n var i = start\n if step < 0:\n while i > ends:\n yield i\n i += step\n elif step > 0:\n while i < ends:\n yield i\n i += step\n iterator range(ends: int): int = (for i in 0..<ends: yield i)\n iterator range(start: int, ends: int): int = (for i in\n start..<ends: yield i)\n\n #joinが非stringでめちゃくちゃ遅いやつのパッチ\n proc join*[T: not string](a: openArray[T], sep: string = \"\"): string = a.mapit($it).join(sep)\n" ImportExpand "cplib/utils/binary_search.nim" <=== "when not declared CPLIB_UTILS_BINARY_SEARCH:\n const CPLIB_UTILS_BINARY_SEARCH* = 1\n proc meguru_bisect*(ok, ng: int, is_ok: proc(x: int): bool): int =\n var\n ok = ok\n ng = ng\n while abs(ok - ng) > 1:\n var mid = (ok + ng) div 2\n if is_ok(mid): ok = mid\n else: ng = mid\n return ok\n\n proc meguru_bisect*(ok, ng: SomeFloat, is_ok: proc(x: SomeFloat): bool, eps: SomeFloat = 1e-10): SomeFloat =\n var\n ok = ok\n ng = ng\n while abs(ok - ng) > eps and abs(ok - ng) / max(ok, ng) > eps:\n var mid = (ok + ng) / 2\n if is_ok(mid): ok = mid\n else: ng = mid\n return ok\n" var N,M,K = ii() if K >= (N-1)+(M-1): echo 10**9 quit() var A = newseqwith(N,lii(M)) proc is_ok(arg:int):bool= var X = newSeqWith(N,newseqwith(M,-1)) for i in range(N): for j in range(M): if A[i][j] < arg: X[i][j] = 1 else: X[i][j] = 0 var d = initDeque[(int,int,int)]() d.addLast((0,0,X[0][0])) var cost = newSeqWith(N,newSeqwith(M,INF)) cost[0][0] = X[0][0] while len(d) != 0: var (i,j,c) = d.popFirst() if c != cost[i][j]: continue for (di,dj) in [(1,0),(-1,0),(0,-1),(0,1)]: if i+di in 0..<N and j+dj in 0..<M and cost[i+di][j+dj] > c+X[i+di][j+dj]: if X[i+di][j+dj] == 0: cost[i+di][j+dj] = c d.addFirst((i+di,j+dj,c)) else: cost[i+di][j+dj] = c+1 d.addFirst((i+di,j+dj,c+1)) return cost[^1][^1] <= K echo meguru_bisect(0,10**9+1,is_ok)