結果
問題 | No.2860 Heal Slimes |
ユーザー | kemuniku |
提出日時 | 2024-08-25 16:14:38 |
言語 | Nim (2.0.2) |
結果 |
WA
|
実行時間 | - |
コード長 | 10,097 bytes |
コンパイル時間 | 3,700 ms |
コンパイル使用メモリ | 91,280 KB |
実行使用メモリ | 14,184 KB |
最終ジャッジ日時 | 2024-08-25 16:14:52 |
合計ジャッジ時間 | 9,402 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 94 ms
10,996 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 38 ms
11,108 KB |
testcase_11 | AC | 39 ms
10,876 KB |
testcase_12 | AC | 40 ms
10,968 KB |
testcase_13 | AC | 39 ms
11,172 KB |
testcase_14 | AC | 40 ms
10,932 KB |
testcase_15 | AC | 50 ms
11,000 KB |
testcase_16 | AC | 51 ms
11,092 KB |
testcase_17 | AC | 50 ms
11,044 KB |
testcase_18 | AC | 49 ms
11,096 KB |
testcase_19 | AC | 50 ms
11,100 KB |
testcase_20 | AC | 35 ms
13,136 KB |
testcase_21 | AC | 42 ms
13,204 KB |
testcase_22 | AC | 32 ms
12,156 KB |
testcase_23 | AC | 46 ms
13,764 KB |
testcase_24 | AC | 41 ms
13,480 KB |
testcase_25 | AC | 28 ms
13,016 KB |
testcase_26 | AC | 23 ms
12,108 KB |
testcase_27 | AC | 36 ms
13,324 KB |
testcase_28 | AC | 37 ms
13,688 KB |
testcase_29 | AC | 32 ms
12,884 KB |
testcase_30 | AC | 37 ms
13,840 KB |
testcase_31 | AC | 37 ms
13,980 KB |
testcase_32 | AC | 38 ms
13,852 KB |
testcase_33 | AC | 38 ms
13,908 KB |
testcase_34 | AC | 42 ms
14,052 KB |
testcase_35 | AC | 38 ms
13,976 KB |
testcase_36 | AC | 35 ms
13,768 KB |
testcase_37 | AC | 37 ms
13,976 KB |
testcase_38 | AC | 36 ms
13,820 KB |
testcase_39 | AC | 36 ms
13,984 KB |
testcase_40 | AC | 46 ms
13,912 KB |
testcase_41 | AC | 50 ms
13,836 KB |
testcase_42 | AC | 46 ms
13,916 KB |
testcase_43 | AC | 54 ms
13,840 KB |
testcase_44 | AC | 48 ms
14,116 KB |
testcase_45 | AC | 45 ms
13,772 KB |
testcase_46 | AC | 49 ms
14,112 KB |
testcase_47 | AC | 47 ms
13,816 KB |
testcase_48 | AC | 46 ms
14,184 KB |
testcase_49 | AC | 49 ms
13,824 KB |
testcase_50 | AC | 56 ms
13,768 KB |
testcase_51 | AC | 49 ms
13,768 KB |
testcase_52 | AC | 49 ms
13,908 KB |
testcase_53 | AC | 45 ms
13,912 KB |
testcase_54 | AC | 50 ms
13,764 KB |
testcase_55 | AC | 44 ms
13,904 KB |
testcase_56 | AC | 56 ms
13,916 KB |
testcase_57 | AC | 53 ms
13,828 KB |
testcase_58 | AC | 46 ms
13,760 KB |
testcase_59 | AC | 46 ms
13,760 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 =\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/str/hash_string.nim" <=== "import random\ntype HashString* =object\n hash* :uint\n size:int\nconst MASK30 = (1u shl 30) - 1\nconst MASK31 = (1u shl 31) - 1\nconst RH_MOD = (1u shl 61) - 1\nconst POW_CALC = 500000\n\nrandomize()\n\nproc calc_mod(x: uint): uint =\n result = (x shr 61) + (x and RH_MOD)\n if result >= RH_MOD:\n result -= RH_MOD\n\nproc mul(a, b: uint): uint =\n let\n a_upper = a shr 31\n a_lower = a and MASK31\n b_upper = b shr 31\n b_lower = b and MASK31\n mid = a_lower * b_upper + a_upper * b_lower\n mid_upper = mid shr 30\n mid_lower = mid and MASK30\n result = a_upper * b_upper * 2 + mid_upper + (mid_lower shl 31) + a_lower * b_lower\n\n\nproc inner_pow(a:uint, n: int): uint =\n var a = a\n var n = n\n result = 1\n while n > 0:\n if (n and 1) != 0:\n result = mul(result, a).calc_mod\n a = mul(a, a).calc_mod\n n = n shr 1\n\nlet hashstring_base:uint = rand(129u..(1u shl 30))\nlet inv_hashstring_base:uint = inner_pow(hashstring_base,int(RH_MOD)-2)\nvar pows : seq[uint] = newseq[uint](POW_CALC+1)\nvar invpows : seq[uint] = newseq[uint](POW_CALC+1)\npows[0] = 1\ninvpows[0] = 1\nfor i in 1..POW_CALC:\n pows[i] = (mul(pows[i-1],hashstring_base).calc_mod)\n invpows[i] = (mul(invpows[i-1],inv_hashstring_base).calc_mod)\n\nproc base_pow(n:int):uint=\n if n >= len(pows):\n return inner_pow(hashstring_base,n)\n else:\n return pows[n]\n\nproc tohash*(S:string):HashString=\n var hash = 0u\n var tmp = 1u\n for i in countdown(len(S)-1,0,1):\n hash = (hash+mul(uint(int(S[i])),tmp)).calc_mod\n tmp = mul(tmp,hashstring_base).calc_mod \n result = HashString(hash:hash,size:len(S))\n\nproc tohash*(S:char):HashString=\n result = HashString(hash:uint(int(S)),size:1)\n\nproc `&`*(L,R:HashString):HashString=\n result = HashString(hash:(mul(L.hash,base_pow(R.size)).calc_mod+R.hash).calc_mod,size:L.size+R.size)\n\nproc `==`*(L,R:HashString):bool=\n return (L.size == R.size) and (L.hash == R.hash)\n\nproc len*(H:HashString):int=int(H.size)\n\nproc `*`*(H:HashString,x:int):HashString=\n result = \"\".toHash()\n var\n x = x\n tmp = H\n while x > 0:\n if x mod 2 != 0: result = result&tmp\n if x > 1: tmp = tmp & tmp\n x = x shr 1\n\nproc removePrefix*(H,suffix:HashString):HashString=\n var hash = (H.hash + (RH_MOD - mul(suffix.hash,base_pow(len(H)-len(suffix))).calc_mod)).calc_mod\n var l = len(H)-len(suffix)\n return HashString(hash:hash,size:l)\n\ntype RollingHashBase = ref object\n S : string\n prefixs : seq[uint]\n size : int \n\ntype RollingHash* = object\n R : RollingHashBase\n l : int\n r : int\n\nproc len*(S:RollingHashBase):int=\n return int(S.size)\n\nproc len*(S:RollingHash):int=\n return int(S.r-S.l)\n\nproc get_substring(R:RollingHashBase,l,r:int):RollingHash=\n # 半開区間とする。\n # 空文字列用にr=0も許容していることに注意。\n # 空文字列はl=0,r=0のみ許容している。\n assert l in 0..<R.size and r in 0..R.size and (l < r or (l == 0 and r == 0))\n result.R = R\n result.l = l\n result.r = r\n\nproc `[]`*(R:RollingHashBase,slice:HSlice[int,int]):RollingHash=\n assert slice.a >= 0 and slice.b >= 0\n return R.get_substring(slice.a,slice.b+1)\n\n\nproc `[]`*(S:RollingHash,slice:HSlice[int,int]):RollingHash=\n if len(slice) == 0:\n return S.R.get_substring(0,0)\n assert slice.a in 0..<len(S) and slice.b in 0..<len(S)\n return S.R.get_substring(S.l+slice.a,S.l+slice.b+1)\n\nproc gethash(S:RollingHash,slice:HSlice[int,int]):uint=\n return (S.R.prefixs[(S.l+slice.b+1)] + (RH_MOD - mul(S.R.prefixs[S.l+slice.a],base_pow(((S.l+slice.b+1)-(S.l+slice.a)))).calc_mod)).calc_mod\n\n\nproc `[]`*(S:RollingHash,idx:int):char=\n return S.R.S[idx+int(S.l)]\n\nproc initRollingHash*(S:string):RollingHash=\n var rolling = RollingHashBase()\n rolling.S = S\n rolling.prefixs = newSeq[uint](len(S)+1)\n rolling.prefixs[0] = 0\n for i in 1..len(S):\n rolling.prefixs[i] = (mul(rolling.prefixs[i-1],hashstring_base) + uint(int(S[i-1]))).calc_mod()\n rolling.size = (len(S))\n return rolling[0..<len(S)]\n\n\n\nconverter toHashString*(self:RollingHash):HashString=\n return HashString(hash:(self.R.prefixs[self.r] + (RH_MOD - mul(self.R.prefixs[self.l],base_pow(self.r-self.l)).calc_mod)).calc_mod,size:self.r-self.l)\n\nproc`$`*(S:RollingHash):string=\n return S.R.S[S.l..<S.r]\n\nproc `==`*(S,T:RollingHash):bool=\n return len(S) == len(T) and (S.R.prefixs[S.r] + (RH_MOD - mul(S.R.prefixs[S.l],base_pow(S.r-S.l)).calc_mod)).calc_mod == \n (T.R.prefixs[T.r] + (RH_MOD - mul(T.R.prefixs[T.l],base_pow(T.r-T.l)).calc_mod)).calc_mod\n\nproc LCP*(S,T:RollingHash):int=\n var ok = 0\n var ng = min(len(S),len(T))+1\n while ng-ok > 1:\n var mid = (ok + ng) div 2\n if S.gethash(0..<mid) == T.gethash(0..<mid): ok = mid\n else: ng = mid\n return ok\n\nproc cmp*(S,T:RollingHash):int=\n var S = S\n var T = T\n var flg = 1\n if len(S) > len(T):\n swap(S,T)\n flg *= -1\n var lcp = LCP(S,T)\n if len(S) == lcp:\n if len(S) == len(T):\n return 0\n else:\n return -1*flg\n else:\n if S[lcp] < T[lcp]:\n return -1*flg\n else:\n return flg\n\nproc `<`*(S,T:RollingHash):bool=\n return cmp(S,T) < 0\n" var T = ii() for i in range(T): block test: var N,K,X = ii() var H = lii(N) var sa = newseqwith(N,0) var now = 0 for i in range(N): sa[i] = H[i] - now now = H[i] for k in range(K): var now = 0 for i in reversed(range(k,N,K).toseq()): if sa[i] < 0: now += sa[i] if i != 0: if sa[i] % X != 0: echo "No" break test if now < 0 and (N % K != k): echo "No" break test else: now += sa[i] if i != 0: if sa[i] % X != 0: echo "No" break test if k != 0: if now != 0: if (N % K == k): if now > 0: echo "No" break test else: echo "No" break test echo "Yes"