結果

問題 No.443 GCD of Permutation
ユーザー titiatitia
提出日時 2023-05-11 01:35:45
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,174 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 79,232 KB
最終ジャッジ日時 2023-08-18 02:16:50
合計ジャッジ時間 5,407 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,784 KB
testcase_01 AC 95 ms
71,856 KB
testcase_02 AC 95 ms
71,532 KB
testcase_03 AC 95 ms
71,632 KB
testcase_04 AC 96 ms
71,576 KB
testcase_05 AC 94 ms
71,768 KB
testcase_06 AC 95 ms
71,652 KB
testcase_07 AC 96 ms
71,788 KB
testcase_08 AC 95 ms
71,540 KB
testcase_09 AC 98 ms
71,372 KB
testcase_10 AC 97 ms
71,576 KB
testcase_11 AC 96 ms
71,724 KB
testcase_12 AC 93 ms
71,640 KB
testcase_13 AC 98 ms
71,736 KB
testcase_14 RE -
testcase_15 AC 104 ms
77,148 KB
testcase_16 AC 103 ms
76,704 KB
testcase_17 AC 103 ms
76,828 KB
testcase_18 RE -
testcase_19 AC 102 ms
76,740 KB
testcase_20 RE -
testcase_21 AC 104 ms
76,656 KB
testcase_22 AC 95 ms
71,464 KB
testcase_23 AC 95 ms
71,372 KB
testcase_24 AC 96 ms
71,624 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
from collections import Counter

S=input()
C=Counter(S)

X=sorted(S,reverse=True)
while X[-1]=="0" and len(X)>0:
    X.pop()

X.reverse()

if len(X)<1000:
    ANS=int("".join(X))
else:
    ANS=0

for i in range(10):
    for j in range(i+1,10):
        if C[str(i)]>0 and C[str(j)]>0:
            a=(10*j+i)-(10*i+j)
            ANS=gcd(ANS,a)

        if C[str(i)]>=2 and C[str(j)]>0:
            a=(100*j+10*i+i)-(100*i+10*j+i)
            b=(100*j+10*i+i)-(100*i+10*i+j)
            ANS=gcd(ANS,a,b)

        if C[str(j)]>=2 and C[str(i)]>0:
            a=(100*j+10*j+i)-(100*j+10*i+j)
            b=(100*j+10*j+i)-(100*i+10*j+j)
            ANS=gcd(ANS,a,b)


        for k in range(j+1,10):
            if C[str(i)]>0 and C[str(j)]>0 and C[str(k)]>0:
                a=(100*k+10*j+i)-(100*i+10*j+k)
                b=(100*k+10*j+i)-(100*i+10*k+j)
                c=(100*k+10*j+i)-(100*j+10*i+k)
                d=(100*k+10*j+i)-(100*j+10*k+i)
                e=(100*k+10*j+i)-(100*k+10*i+j)

                ANS=gcd(ANS,a,b,c,d,e)

                
XS=int(S)

for i in range(ANS,-1,-1):
    if ANS%i==0 and XS%i==0:
        print(i)
        break
 
0