結果
問題 | No.2929 Miracle Branch |
ユーザー | prin_kemkem |
提出日時 | 2024-10-12 16:52:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 174 ms / 2,000 ms |
コード長 | 2,773 bytes |
コンパイル時間 | 153 ms |
コンパイル使用メモリ | 82,520 KB |
実行使用メモリ | 100,824 KB |
最終ジャッジ日時 | 2024-10-12 16:52:35 |
合計ジャッジ時間 | 10,049 ms |
ジャッジサーバーID (参考情報) |
judge / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
56,804 KB |
testcase_01 | AC | 40 ms
56,352 KB |
testcase_02 | AC | 43 ms
62,760 KB |
testcase_03 | AC | 41 ms
57,632 KB |
testcase_04 | AC | 45 ms
58,792 KB |
testcase_05 | AC | 45 ms
58,176 KB |
testcase_06 | AC | 51 ms
57,632 KB |
testcase_07 | AC | 45 ms
58,068 KB |
testcase_08 | AC | 41 ms
58,228 KB |
testcase_09 | AC | 41 ms
58,460 KB |
testcase_10 | AC | 41 ms
59,136 KB |
testcase_11 | AC | 42 ms
58,300 KB |
testcase_12 | AC | 42 ms
57,232 KB |
testcase_13 | AC | 42 ms
57,668 KB |
testcase_14 | AC | 41 ms
58,084 KB |
testcase_15 | AC | 41 ms
57,844 KB |
testcase_16 | AC | 41 ms
58,224 KB |
testcase_17 | AC | 40 ms
56,824 KB |
testcase_18 | AC | 65 ms
74,448 KB |
testcase_19 | AC | 63 ms
74,948 KB |
testcase_20 | AC | 68 ms
77,672 KB |
testcase_21 | AC | 70 ms
77,976 KB |
testcase_22 | AC | 41 ms
57,884 KB |
testcase_23 | AC | 73 ms
78,340 KB |
testcase_24 | AC | 115 ms
83,324 KB |
testcase_25 | AC | 70 ms
77,620 KB |
testcase_26 | AC | 52 ms
67,580 KB |
testcase_27 | AC | 60 ms
70,324 KB |
testcase_28 | AC | 44 ms
62,148 KB |
testcase_29 | AC | 45 ms
62,176 KB |
testcase_30 | AC | 49 ms
61,692 KB |
testcase_31 | AC | 43 ms
62,156 KB |
testcase_32 | AC | 43 ms
62,456 KB |
testcase_33 | AC | 84 ms
75,512 KB |
testcase_34 | AC | 172 ms
100,204 KB |
testcase_35 | AC | 171 ms
100,548 KB |
testcase_36 | AC | 55 ms
76,104 KB |
testcase_37 | AC | 165 ms
100,824 KB |
testcase_38 | AC | 171 ms
100,356 KB |
testcase_39 | AC | 168 ms
100,588 KB |
testcase_40 | AC | 167 ms
100,684 KB |
testcase_41 | AC | 164 ms
100,304 KB |
testcase_42 | AC | 174 ms
100,444 KB |
testcase_43 | AC | 154 ms
100,472 KB |
testcase_44 | AC | 153 ms
99,212 KB |
testcase_45 | AC | 42 ms
62,216 KB |
ソースコード
from collections import defaultdict, deque, Counter # from functools import cache # import copy from itertools import combinations, permutations, product, accumulate, groupby, chain # from more_itertools import distinct_permutations from heapq import heapify, heappop, heappush import math import bisect # from pprint import pprint from random import randint, shuffle, randrange # from sortedcontainers import SortedSet, SortedList, SortedDict import sys # sys.setrecursionlimit(2000000) input = lambda: sys.stdin.readline().rstrip('\n') inf = float('inf') mod1 = 10**9+7 mod2 = 998244353 def ceil_div(x, y): return -(-x//y) ################################################# # https://github.com/shakayami/ACL-for-python/blob/master/prime_fact.py from math import gcd import random from collections import Counter def is_probable_prime(n): if n==2: return True if n==1 or n&1==0: return False d=(n-1)>>1 while d&1==0: d>>=1 for k in range(100): a=random.randint(1,n-1) t=d y=pow(a, t, n) while t!=n-1 and y!=1 and y!=n-1: y=(y*y)%n t<<=1 if y!=n-1 and t&1==0: return False return True def _solve(N): if is_probable_prime(N): return N while(True): x=random.randrange(N) c=random.randrange(N) y=(x*x+c)%N d=1 while(d==1): d=gcd(x-y,N) x=(x*x+c)%N y=(y*y+c)%N y=(y*y+c)%N if 1<d<N: return _solve(d) def prime_fact(N): res=Counter() p=2 while(p<=10**4 and N>1): if N%p==0: while(N%p==0): res[p]+=1 N//=p p+=1 while(N>1): p=_solve(N) while(N%p)==0: res[p]+=1 N//=p return res X = int(input()) if X == 1: print(2) print(1, 2) print("b", "g") exit() pf = prime_fact(X) n = 0 ans_e = [] ans_c = [] for p, e in pf.items(): if p == 2: if e%2 == 1: pn = n n += (p+1) if n > 2*10**5: print(-1) exit() ans_c.extend(["g"]*2) ans_c.append("b") if ans_e: ans_e.append((pn, pn+p+1)) for i in range(pn+1, pn+p+1): ans_e.append((i, pn+p+1)) p = 4 e //= 2 pn = n n += (p+1)*e if n > 2*10**5: print(-1) exit() for _ in range(e): ans_c.extend(["g"]*p) ans_c.append("b") if ans_e: ans_e.append((pn, pn+p+1)) for i in range(pn+1, pn+p+1): ans_e.append((i, pn+p+1)) pn += p+1 print(n) for u, v in ans_e: print(u, v) print(*ans_c)