結果

問題 No.2929 Miracle Branch
ユーザー kemunikukemuniku
提出日時 2024-10-12 15:47:30
言語 Nim
(2.0.2)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 4,918 bytes
コンパイル時間 3,862 ms
コンパイル使用メモリ 75,648 KB
実行使用メモリ 13,824 KB
最終ジャッジ日時 2024-10-12 15:47:47
合計ジャッジ時間 14,079 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 4 ms
5,248 KB
testcase_02 AC 4 ms
5,248 KB
testcase_03 AC 4 ms
5,248 KB
testcase_04 AC 5 ms
5,248 KB
testcase_05 AC 4 ms
5,248 KB
testcase_06 AC 4 ms
5,248 KB
testcase_07 AC 4 ms
5,248 KB
testcase_08 AC 4 ms
5,248 KB
testcase_09 AC 4 ms
5,248 KB
testcase_10 AC 4 ms
5,248 KB
testcase_11 AC 4 ms
5,248 KB
testcase_12 AC 4 ms
6,816 KB
testcase_13 AC 4 ms
5,248 KB
testcase_14 AC 4 ms
5,248 KB
testcase_15 AC 5 ms
5,248 KB
testcase_16 AC 5 ms
5,248 KB
testcase_17 AC 4 ms
5,248 KB
testcase_18 AC 6 ms
5,248 KB
testcase_19 AC 7 ms
5,248 KB
testcase_20 AC 10 ms
5,248 KB
testcase_21 AC 15 ms
5,248 KB
testcase_22 AC 4 ms
5,248 KB
testcase_23 AC 26 ms
5,248 KB
testcase_24 AC 88 ms
6,144 KB
testcase_25 AC 14 ms
5,248 KB
testcase_26 AC 5 ms
5,248 KB
testcase_27 AC 5 ms
5,248 KB
testcase_28 AC 3 ms
5,248 KB
testcase_29 AC 4 ms
5,248 KB
testcase_30 AC 4 ms
5,248 KB
testcase_31 AC 4 ms
5,248 KB
testcase_32 AC 3 ms
5,248 KB
testcase_33 AC 4 ms
5,248 KB
testcase_34 AC 277 ms
13,792 KB
testcase_35 AC 277 ms
13,668 KB
testcase_36 AC 4 ms
5,248 KB
testcase_37 AC 285 ms
13,676 KB
testcase_38 AC 279 ms
13,824 KB
testcase_39 AC 283 ms
13,656 KB
testcase_40 AC 274 ms
13,824 KB
testcase_41 AC 273 ms
13,716 KB
testcase_42 AC 283 ms
13,696 KB
testcase_43 AC 277 ms
13,644 KB
testcase_44 AC 282 ms
13,648 KB
testcase_45 AC 4 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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"
#茶色のパスに緑をつけいく
#なんか10^18の素因数分解を求められていないか?
#冷静になると、2*10^5以上の素数があるなら終わりなのでok
#6とかが微妙にコーナーそうで怖い。
#6の作り方として、2と3を作ると5+2で7頂点、直接作っても7頂点
#大丈夫か~
#4がヤバいかも?
#2*2は6頂点食うが、4をつくるなら5頂点で済む。
#2はなるべく4を作った方が効率がいい?
#8は2*2*2で9頂点、2*4で8頂点,8で9頂点

var X = ii()
var tmp = X
var D : seq[int]
if X == 1:
    echo 2
    echo 1," ",2
    echo "b g"
    quit()

var div2 = 0
while tmp % 2 == 0:
    tmp //= 2
    div2 += 1

for x in 3..(200000):
    while tmp % x == 0:
        tmp //= x
        D.add(x)

if tmp != 1:
    echo -1
    quit()

var need = (div2//2)*5+(div2%2)*3+(len(D)+sum(D))

if need > 200000:
    echo -1
    quit()

var N = need
var edges : seq[(int,int)]
var B = (div2//2)+(div2%2)+len(D)

for i in range(B-1):
    edges.add((i,i+1))

var now = B
for i in range(len(D)):
    for x in range(D[i]):
        edges.add((now,i))
        now += 1


for i in range(len(D),len(D)+(div2//2)):
    for x in range(4):
        edges.add((now,i))
        now += 1

for i in range(len(D)+(div2//2),(div2%2)+len(D)+(div2//2)):
    for x in range(2):
        edges.add((now,i))
        now += 1

assert (div2%2)+len(D)+(div2//2) == B
var C = newSeqWith(N,'g')

for i in range(B):
    C[i] = 'b'

assert len(edges) == N-1

echo N
for i in range(N-1):
    echo edges[i][0]+1," ",edges[i][1]+1

echo C.join(" ")
0