結果

問題 No.443 GCD of Permutation
ユーザー titiatitia
提出日時 2023-05-11 01:17:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 870 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 8,672 KB
最終ジャッジ日時 2023-08-18 02:08:52
合計ジャッジ時間 1,969 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 19 ms
8,656 KB
testcase_02 AC 19 ms
8,600 KB
testcase_03 WA -
testcase_04 AC 20 ms
8,584 KB
testcase_05 AC 19 ms
8,608 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 20 ms
8,604 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 20 ms
8,496 KB
testcase_15 AC 20 ms
8,592 KB
testcase_16 WA -
testcase_17 AC 20 ms
8,504 KB
testcase_18 AC 21 ms
8,508 KB
testcase_19 AC 20 ms
8,668 KB
testcase_20 AC 20 ms
8,588 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 19 ms
8,496 KB
testcase_25 AC 20 ms
8,548 KB
testcase_26 AC 20 ms
8,532 KB
testcase_27 WA -
testcase_28 AC 20 ms
8,500 KB
testcase_29 WA -
testcase_30 AC 20 ms
8,548 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
from collections import Counter

S=input()
C=Counter(S)

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=(10*j+i)-(10*i+i)
            ANS=gcd(ANS,a)

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

        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+k)
                ANS=gcd(ANS,a,b,c,d,e)

                

if ANS==0:
    print(S)
else:
    print(ANS)
0