結果

問題 No.443 GCD of Permutation
ユーザー d9etd9et
提出日時 2020-04-17 23:30:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 582 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 62,060 KB
最終ジャッジ日時 2024-04-14 15:40:53
合計ジャッジ時間 2,774 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 42 ms
54,700 KB
testcase_02 AC 42 ms
55,808 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 43 ms
54,476 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 47 ms
54,184 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 46 ms
60,696 KB
testcase_15 AC 46 ms
60,696 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 46 ms
61,388 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
from collections import Counter
def gcds(ls):
  ret = 0
  for i in ls:
    if ret*i == 0:
      ret = max(ret,i)
    else:
      ret = gcd(ret,i)
    print(ret,i)
  return ret
n = input()
c = Counter(n)
d = list(int(i) for i in c.keys())
ans = 1
if len(d) == 1:
  ans = n
else:
  if len(d) == 2 and 0 in d:
    ans *= max(d)
  elif gcds(d) != 1:
    b = gcds(d)
    if b%3:
      ans *= b
    else:
      ans *= b//3
    dsum = 0
    for i,j in c.items():
      dsum += int(i)*j
    if dsum%9 == 0:
      ans *= 9
    elif dsum%3 == 0:
      ans *= 3
print(ans)
0