結果

問題 No.927 Second Permutation
ユーザー hedwig100hedwig100
提出日時 2020-04-13 23:11:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 840 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 11,940 KB
実行使用メモリ 10,352 KB
最終ジャッジ日時 2023-10-26 04:28:57
合計ジャッジ時間 3,125 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
9,948 KB
testcase_01 AC 30 ms
9,948 KB
testcase_02 AC 29 ms
9,948 KB
testcase_03 AC 29 ms
9,948 KB
testcase_04 AC 30 ms
9,948 KB
testcase_05 AC 29 ms
9,948 KB
testcase_06 AC 30 ms
9,948 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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 AC 107 ms
10,156 KB
testcase_25 AC 60 ms
10,124 KB
testcase_26 AC 55 ms
10,076 KB
testcase_27 AC 41 ms
10,028 KB
testcase_28 AC 56 ms
10,064 KB
testcase_29 AC 50 ms
10,080 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(1,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])
    
    print(''.join(ans[::-1]))

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