結果

問題 No.927 Second Permutation
ユーザー hedwig100hedwig100
提出日時 2020-04-14 16:52:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-09 13:11:45
合計ジャッジ時間 3,721 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,624 KB
testcase_01 AC 29 ms
10,496 KB
testcase_02 AC 29 ms
10,624 KB
testcase_03 AC 29 ms
10,624 KB
testcase_04 AC 30 ms
10,624 KB
testcase_05 AC 30 ms
10,496 KB
testcase_06 AC 30 ms
10,624 KB
testcase_07 AC 30 ms
10,496 KB
testcase_08 AC 47 ms
10,752 KB
testcase_09 AC 30 ms
10,624 KB
testcase_10 AC 57 ms
10,880 KB
testcase_11 AC 74 ms
11,008 KB
testcase_12 AC 51 ms
10,880 KB
testcase_13 AC 33 ms
10,624 KB
testcase_14 AC 57 ms
10,880 KB
testcase_15 AC 50 ms
11,008 KB
testcase_16 AC 78 ms
10,880 KB
testcase_17 AC 78 ms
11,008 KB
testcase_18 AC 79 ms
10,880 KB
testcase_19 AC 79 ms
11,008 KB
testcase_20 AC 77 ms
11,008 KB
testcase_21 AC 78 ms
10,880 KB
testcase_22 AC 80 ms
10,880 KB
testcase_23 AC 78 ms
10,880 KB
testcase_24 AC 99 ms
10,880 KB
testcase_25 AC 57 ms
10,880 KB
testcase_26 AC 50 ms
10,752 KB
testcase_27 AC 39 ms
10,752 KB
testcase_28 AC 54 ms
10,880 KB
testcase_29 AC 49 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    x = input()
    cnt = [0] * 10
    num = '0123456789'

    for i in x:
        for j in range(10):
            if num[j] == i:
                cnt[j] += 1
                break

    a,b = -1,-1
    for i in range(10):
        if cnt[i] > 0:
            if a < 0:
                a = i
            else:
                b = i
                break
    if b < 0:
        print(-1)
        return

    ans = []
    for i in range(10):
        if i == a:
            ans.append(num[b] + num[a] * (cnt[a] - 1))
        elif i == b:
            ans.append(num[b] * (cnt[b] - 1) + num[a])
        else:
            ans.append(num[i] * cnt[i])
    
    
    answer = ''.join(ans[::-1])
    if answer[0] == '0':
        print(-1)
        return

    print(answer)

if __name__ =='__main__':
    main()   
0