結果
問題 | No.1704 Many Bus Stops (easy) |
ユーザー | yuly3 |
提出日時 | 2021-11-03 14:20:56 |
言語 | Nim (2.0.2) |
結果 |
AC
|
実行時間 | 538 ms / 2,000 ms |
コード長 | 5,677 bytes |
コンパイル時間 | 3,127 ms |
コンパイル使用メモリ | 74,872 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-13 03:47:08 |
合計ジャッジ時間 | 18,301 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 498 ms
6,816 KB |
testcase_02 | AC | 167 ms
6,816 KB |
testcase_03 | AC | 164 ms
6,820 KB |
testcase_04 | AC | 162 ms
6,820 KB |
testcase_05 | AC | 159 ms
6,816 KB |
testcase_06 | AC | 164 ms
6,816 KB |
testcase_07 | AC | 160 ms
6,816 KB |
testcase_08 | AC | 157 ms
6,820 KB |
testcase_09 | AC | 159 ms
6,820 KB |
testcase_10 | AC | 165 ms
6,820 KB |
testcase_11 | AC | 162 ms
6,820 KB |
testcase_12 | AC | 158 ms
6,816 KB |
testcase_13 | AC | 158 ms
6,816 KB |
testcase_14 | AC | 155 ms
6,820 KB |
testcase_15 | AC | 163 ms
6,820 KB |
testcase_16 | AC | 166 ms
6,816 KB |
testcase_17 | AC | 168 ms
6,820 KB |
testcase_18 | AC | 161 ms
6,816 KB |
testcase_19 | AC | 167 ms
6,820 KB |
testcase_20 | AC | 166 ms
6,820 KB |
testcase_21 | AC | 163 ms
6,816 KB |
testcase_22 | AC | 486 ms
6,816 KB |
testcase_23 | AC | 498 ms
6,816 KB |
testcase_24 | AC | 488 ms
6,820 KB |
testcase_25 | AC | 489 ms
6,820 KB |
testcase_26 | AC | 485 ms
6,816 KB |
testcase_27 | AC | 497 ms
6,816 KB |
testcase_28 | AC | 478 ms
6,816 KB |
testcase_29 | AC | 510 ms
6,816 KB |
testcase_30 | AC | 491 ms
6,820 KB |
testcase_31 | AC | 509 ms
6,816 KB |
testcase_32 | AC | 499 ms
6,820 KB |
testcase_33 | AC | 503 ms
6,820 KB |
testcase_34 | AC | 482 ms
6,816 KB |
testcase_35 | AC | 494 ms
6,820 KB |
testcase_36 | AC | 501 ms
6,816 KB |
testcase_37 | AC | 497 ms
6,820 KB |
testcase_38 | AC | 538 ms
6,820 KB |
testcase_39 | AC | 501 ms
6,824 KB |
testcase_40 | AC | 490 ms
6,820 KB |
testcase_41 | AC | 509 ms
6,816 KB |
コンパイルメッセージ
/home/judge/data/code/Main.nim(5, 5) Warning: imported and not used: 'algorithm' [UnusedImport] /home/judge/data/code/Main.nim(13, 5) Warning: imported and not used: 'strformat' [UnusedImport] /home/judge/data/code/Main.nim(15, 5) Warning: imported and not used: 'sugar' [UnusedImport] /home/judge/data/code/Main.nim(8, 5) Warning: imported and not used: 'heapqueue' [UnusedImport]
ソースコード
when not declared ATCODER_YULY3HEADER_HPP: const ATCODER_YULY3HEADER_HPP* = 1 import algorithm, bitops, deques, heapqueue, math, macros, sets, sequtils, strformat, strutils, sugar, tables proc transLastStmt(n, res, bracketExpr: NimNode): (NimNode, NimNode, NimNode) = # Looks for the last statement of the last statement, etc... case n.kind of nnkIfExpr, nnkIfStmt, nnkTryStmt, nnkCaseStmt: result[0] = copyNimTree(n) result[1] = copyNimTree(n) result[2] = copyNimTree(n) for i in ord(n.kind == nnkCaseStmt)..<n.len: (result[0][i], result[1][^1], result[2][^1]) = transLastStmt(n[i], res, bracketExpr) of nnkStmtList, nnkStmtListExpr, nnkBlockStmt, nnkBlockExpr, nnkWhileStmt, nnkForStmt, nnkElifBranch, nnkElse, nnkElifExpr, nnkOfBranch, nnkExceptBranch: result[0] = copyNimTree(n) result[1] = copyNimTree(n) result[2] = copyNimTree(n) if n.len >= 1: (result[0][^1], result[1][^1], result[2][^1]) = transLastStmt(n[^1], res, bracketExpr) of nnkTableConstr: result[1] = n[0][0] result[2] = n[0][1] if bracketExpr.len == 1: bracketExpr.add([newCall(bindSym"typeof", newEmptyNode()), newCall( bindSym"typeof", newEmptyNode())]) template adder(res, k, v) = res[k] = v result[0] = getAst(adder(res, n[0][0], n[0][1])) of nnkCurly: result[2] = n[0] if bracketExpr.len == 1: bracketExpr.add(newCall(bindSym"typeof", newEmptyNode())) template adder(res, v) = res.incl(v) result[0] = getAst(adder(res, n[0])) else: result[2] = n if bracketExpr.len == 1: bracketExpr.add(newCall(bindSym"typeof", newEmptyNode())) template adder(res, v) = res.add(v) result[0] = getAst(adder(res, n)) macro collect*(init, body: untyped): untyped = runnableExamples: import sets, tables let data = @["bird", "word"] ## seq: let k = collect(newSeq): for i, d in data.pairs: if i mod 2 == 0: d assert k == @["bird"] ## seq with initialSize: let x = collect(newSeqOfCap(4)): for i, d in data.pairs: if i mod 2 == 0: d assert x == @["bird"] ## HashSet: let y = initHashSet.collect: for d in data.items: {d} assert y == data.toHashSet ## Table: let z = collect(initTable(2)): for i, d in data.pairs: {i: d} assert z == {0: "bird", 1: "word"}.toTable let res = genSym(nskVar, "collectResult") expectKind init, {nnkCall, nnkIdent, nnkSym} let bracketExpr = newTree(nnkBracketExpr, if init.kind == nnkCall: init[0] else: init) let (resBody, keyType, valueType) = transLastStmt(body, res, bracketExpr) if bracketExpr.len == 3: bracketExpr[1][1] = keyType bracketExpr[2][1] = valueType else: bracketExpr[1][1] = valueType let call = newTree(nnkCall, bracketExpr) if init.kind == nnkCall: for i in 1 ..< init.len: call.add init[i] result = newTree(nnkStmtListExpr, newVarStmt(res, call), resBody, res) proc nextString*(f: auto = stdin): string = var get = false result = "" while true: let c = f.readChar if c.int > ' '.int: get = true result.add(c) elif get: return proc nextInt*(f: auto = stdin): int = parseInt(f.nextString) proc nextFloat*(f: auto = stdin): float = parseFloat(f.nextString) proc chmax*[T](n: var T, m: T) {.inline.} = n = max(n, m) proc chmin*[T](n: var T, m: T) {.inline.} = n = min(n, m) proc `%=`*[T: SomeInteger](n: var T, m: T) {.inline.} = n = floorMod(n, m) proc `|=`*[T: SomeInteger or bool](n: var T, m: T) {.inline.} = n = n or m proc `&=`*[T: SomeInteger or bool](n: var T, m: T) {.inline.} = n = n and m proc `^=`*[T: SomeInteger or bool](n: var T, m: T) {.inline.} = n = n xor m proc `<<=`*[T: SomeInteger](n: var T, m: T) {.inline.} = n = n shl m proc `>>=`*[T: SomeInteger](n: var T, m: T) {.inline.} = n = n shr m proc modPow*(a: int, k: Natural, MOD = 10^9 + 7): int = var a = a k = k result = 1 while k > 0: if bitand(k, 1) == 1: result = floorMod(result*a, MOD) a = floorMod(a*a, MOD) k = k shr 1 proc modInv*(a: int, MOD = 10^9 + 7): int = return modPow(a, MOD - 2, MOD) proc matVecMul*(A: seq[seq[int]], B: seq[int], MOD = 10^9 + 7): seq[int] = let N = B.len result = newSeq[int](N) for i in 0..<N: for j in 0..<N: result[i] = floorMod(result[i] + floorMod(A[i][j]*B[j], MOD), MOD) proc matMul*(A, B: seq[seq[int]], M = 10^9 + 7): seq[seq[int]] = let N0 = A.len N1 = B[0].len N2 = A[0].len result = newSeqWith(N0, newSeq[int](N1)) for i in 0..<N0: for j in 0..<N1: for k in 0..<N2: result[i][j] = floorMod(result[i][j] + A[i][k]*B[k][j], M) proc matPow*(A: seq[seq[int]], K: Natural, M = 10^9 + 7): seq[seq[int]] = let N = len(A) var A = A K = K result = newSeqWith(N, newSeq[int](N)) for i in 0..<N: result[i][i] = 1 while K > 0: if bitand(K, 1) == 1: result = matMul(result, A, M) A = matMul(A, A, M) K = K shr 1 when isMainModule: const MOD = 10^9 + 7 var T = nextInt() var ans: seq[int] for _ in 0..<T: var N = nextInt() var mat = newSeqWith(6, newSeq[int](6)) for i in 0..2: for j in 0..2: if i == j: mat[i][j] = 1 mat[i + 3][j] = 3 else: mat[i][j + 3] = 1 var vec = matPow(mat, N).matVecMul(@[1, 0, 0, 3, 0, 0]) ans.add(modInv(modPow(3, N + 1))*vec[3] mod MOD) echo ans.join("\n")