結果
問題 | No.2639 Longest Increasing Walk |
ユーザー | kemuniku |
提出日時 | 2024-02-20 00:08:42 |
言語 | Nim (2.0.2) |
結果 |
AC
|
実行時間 | 125 ms / 2,000 ms |
コード長 | 6,361 bytes |
コンパイル時間 | 3,426 ms |
コンパイル使用メモリ | 78,044 KB |
実行使用メモリ | 26,728 KB |
最終ジャッジ日時 | 2024-09-29 03:18:16 |
合計ジャッジ時間 | 5,997 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 69 ms
26,672 KB |
testcase_05 | AC | 107 ms
26,652 KB |
testcase_06 | AC | 103 ms
18,084 KB |
testcase_07 | AC | 107 ms
18,152 KB |
testcase_08 | AC | 105 ms
18,132 KB |
testcase_09 | AC | 125 ms
26,728 KB |
testcase_10 | AC | 92 ms
11,904 KB |
testcase_11 | AC | 80 ms
11,368 KB |
testcase_12 | AC | 14 ms
6,820 KB |
testcase_13 | AC | 96 ms
11,888 KB |
testcase_14 | AC | 55 ms
9,392 KB |
testcase_15 | AC | 2 ms
6,816 KB |
testcase_16 | AC | 3 ms
6,816 KB |
testcase_17 | AC | 48 ms
9,472 KB |
testcase_18 | AC | 68 ms
11,904 KB |
testcase_19 | AC | 18 ms
6,820 KB |
testcase_20 | AC | 40 ms
8,192 KB |
testcase_21 | AC | 82 ms
11,392 KB |
testcase_22 | AC | 29 ms
6,816 KB |
testcase_23 | AC | 2 ms
6,816 KB |
testcase_24 | AC | 2 ms
6,820 KB |
testcase_25 | AC | 2 ms
6,820 KB |
testcase_26 | AC | 2 ms
6,820 KB |
testcase_27 | AC | 2 ms
6,816 KB |
testcase_28 | AC | 2 ms
6,816 KB |
testcase_29 | AC | 1 ms
6,820 KB |
testcase_30 | AC | 2 ms
6,820 KB |
testcase_31 | AC | 1 ms
6,816 KB |
testcase_32 | AC | 2 ms
6,820 KB |
ソースコード
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 = (((x mod y)+y) mod y)\n proc `//`(x: int, y: int): int = (((x) - (x%y)) div (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, y: int): int = 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: 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 proc `@`(x: int): seq[int] =\n for i in 0..<64:\n if x[i]:\n result.add(i)\n #便利な変換\n proc `!`(x: char, a = '0'): int = int(x)-int(a)\n #定数\n const INF = int(3300300300300300491)\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" ImportExpand "cplib/collections/segtree.nim" <=== "when not declared CPLIB_COLLECTIONS_SEGTREE:\n const CPLIB_COLLECTIONS_SEGTREE* = 1\n import algorithm\n type SegmentTree*[T] = ref object\n default: T\n merge: proc(x: T, y: T): T\n arr*: seq[T]\n lastnode: int\n length: int\n proc initSegmentTree*[T](v: seq[T], merge: proc(x: T, y: T): T, default: T): SegmentTree[T] =\n ## セグメントツリーを生成します。\n ## vに元となるリスト、mergeに二つの区間をマージする関数、デフォルトに単位元を与えてください。\n var lastnode = 1\n while lastnode < len(v):\n lastnode*=2\n var arr = newSeq[T](2*lastnode)\n arr.fill(default)\n var self = SegmentTree[T](default: default, merge: merge, arr: arr, lastnode: lastnode, length: len(v))\n #1-indexedで作成する\n for i in 0..<len(v):\n self.arr[self.lastnode+i] = v[i]\n for i in countdown(lastnode-1, 1):\n self.arr[i] = self.merge(self.arr[2*i], self.arr[2*i+1])\n return self\n\n proc update*[T](self: SegmentTree[T], x: Natural, val: T) =\n ## xの要素をvalに変更します。\n assert x < self.length\n var x = x\n x += self.lastnode\n self.arr[x] = val\n while x > 1:\n x = x shr 1\n self.arr[x] = self.merge(self.arr[2*x], self.arr[2*x+1])\n proc get*[T](self: SegmentTree[T], q_left: Natural, q_right: Natural): T =\n ## 半解区間[q_left,q_right)についての演算結果を返します。\n assert q_left <= q_right and 0 <= q_left and q_right <= self.length\n var q_left = q_left\n var q_right = q_right\n q_left += self.lastnode\n q_right += self.lastnode\n var (lres, rres) = (self.default, self.default)\n while q_left < q_right:\n if (q_left and 1) > 0:\n lres = self.merge(lres, self.arr[q_left])\n q_left += 1\n if (q_right and 1) > 0:\n q_right -= 1\n rres = self.merge(self.arr[q_right], rres)\n q_left = q_left shr 1\n q_right = q_right shr 1\n return self.merge(lres, rres)\n proc get*[T](self: SegmentTree[T], segment: HSlice[int, int]): T =\n assert segment.a <= segment.b + 1 and 0 <= segment.a and segment.b+1 <= self.length\n return self.get(segment.a, segment.b+1)\n proc `[]`*[T](self: SegmentTree[T], index: Natural): T =\n assert index < self.length\n return self.arr[index+self.lastnode]\n proc `[]=`*[T](self: SegmentTree[T], index: Natural, val: T) =\n assert index < self.length\n self.update(index, val)\n proc get_all*[T](self: SegmentTree[T]): T =\n ## [0,len(self))区間の演算結果をO(1)で返す\n return self.arr[1]\n proc len*[T](self: SegmentTree[T]): int =\n return self.length\n\n template newSegWith*(V, merge, default: untyped): untyped =\n initSegmentTree(V, (l, r{.inject.}: typeof(default)) => merge, default)\n\n" var H,W = ii() var A = newseqwith(H,newSeqWith(W,ii())) var X : seq[(int,int,int)] for i in range(H): for j in range(W): X.add (A[i][j],i,j) X.sort() var DP = newseqwith(H,newSeqWith(W,-INF)) for (a,i,j) in X: DP[i][j] = 1 for (di,dj) in [(0,1),(1,0),(-1,0),(0,-1)]: if i+di in 0..<H and j+dj in 0..<W and A[i][j] > A[i+di][j+dj]: DP[i][j].max = DP[i+di][j+dj] + 1 echo DP.mapit(max(it)).max()