結果

問題 No.1880 Many Ways
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-03-29 13:45:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,583 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 55,668 KB
最終ジャッジ日時 2024-04-25 15:23:49
合計ジャッジ時間 13,340 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,208 KB
testcase_01 AC 36 ms
53,112 KB
testcase_02 AC 37 ms
54,356 KB
testcase_03 WA -
testcase_04 AC 37 ms
54,448 KB
testcase_05 AC 38 ms
53,688 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 40 ms
54,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #




########################################
from heapq import heappush, heappop
def dijkstra( G, s, INF=10 ** 18):
    """
    https://tjkendev.github.io/procon-library/python/graph/dijkstra.html
    O((|E|+|V|)log|V|)
    V: 頂点数
    G[v] = [(nod, cost)]:
        頂点vから遷移可能な頂点(nod)とそのコスト(cost)
    s: 始点の頂点"""

    N=len(G)
    N+=1
    dist = [INF] * N
    hp = [(0, s)]  # (c, v)
    dist[s] = 0
    cnt=[0]*N
    cnt[s]=1
    while hp:
        c, v = heappop(hp)  #vまで行くコストがc
        if dist[v] < c:
            continue
        for u, cost in G[v]:
            if dist[v] + cost < dist[u]:
                dist[u] = dist[v] + cost
                cnt[u]=cnt[v]
                heappush(hp, (dist[u], u))
            elif dist[v]+cost==dist[u]:
                cnt[u]+=cnt[v]
    return dist,cnt
##################################################





a=int(input())
if a==0:
    print(2,0)
    exit()
if a==1:
    print(1,0)
    exit()

k=1
while 2**(k+1)<=a:k+=1

n=128
ans=[]
root=[[] for i in range(n+1)]
def add(u,v):
    ans.append((u,v))
    root[u].append((v,1))
    root[v].append((u,1))

add(1,2)
add(1,3)
for i in range(1,k):
    add(2*i,2*i+2)
    add(2*i,2*i+3)
    add(2 * i+1, 2 * i + 2)
    add(2 * i+1, 2 * i + 3)

add(2*k,n)
add(2*k+1,n)
add(1,2*k+2)
for i in range(1,k):
    add(2*k+i+1,2*k+i+2)
a-=2**k
for i in range(k,-1,-1):
    if a>=2**i:
        if i==k-1:
            add(1,2)
        else:
            add(2*k+k-i,2*(k-i)+1)
        a-=2**i

print(n,len(ans))
for x,y in ans:print(x,y)
0