結果

問題 No.2593 Reorder and Mod 120
ユーザー Atsushi TamuraAtsushi Tamura
提出日時 2023-12-30 23:34:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 4,195 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2023-12-30 23:34:37
合計ジャッジ時間 2,309 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,240 KB
testcase_01 RE -
testcase_02 AC 32 ms
10,240 KB
testcase_03 AC 31 ms
10,240 KB
testcase_04 AC 31 ms
10,240 KB
testcase_05 AC 32 ms
10,240 KB
testcase_06 AC 30 ms
10,240 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#最大で40みたいだね
#https://yukicoder.me/problems/no/2593
s=input()
a=[i for i in range(120)]
n_str=input()
n_int=int(n_str)
n_str_list=list(n_str)
n_int_list=sorted([int(i) for i in n_str_list]) #[1,1,2,3,4,4,5]

#後ほど重要
exchange_list_1 = []
exchange_list_10 = []
exchange_list_100 = []

#以降、threelistの3つの数字を引いたものが、1000の位以上の%120の値
n_div_120 = 0
for i in n_int_list:
    n_div_120 += i
n_div_120 = n_div_120 % 120 

#最初の最小の3桁の数字
three_list = [n_int_list[0], n_int_list[1], n_int_list[2]]
#リストから最小の3つを削除
for _ in range(3):
    n_int_list.pop(0) 

while True: #一番最後のbreakにかかっています
    three_int = three_list[0]*100 + three_list[1]*10 + three_list[2] 
    #print(a)
    #print(three_int)
    #d=input('繰り返し')
#現在の、1000の位以上のmod120
    x = (120 + n_div_120 - (three_list[0] + three_list[1] + three_list[2]))%120
    #現在の最小3桁のmod120
    y = three_int % 120
    #合計のmod120, それをaから取り除く
    z = (40*x + y) % 120
    if z in a:
        a.remove(z)

    #次の数字への移行
    #一の位にすでに代入されたやつらが0,2,3,..的に蓄積されていくリスト
    exchange_list_1.append(three_list[2])

    #一の位を元データベースの正しい位置に戻す
    for i in range(len(n_str)-3):
        if n_int_list[i]>=three_list[2]:
            n_int_list.insert(i, three_list[2])
            break
    else:
        n_int_list.append(three_list[2])

    #3リストの一の位を削除
    three_list.pop()
    #いままでの一の位より大きい最小の数をリストから探す物語
    for i in n_int_list:
        if i not in exchange_list_1:
            three_list.append(i) 
            n_int_list.remove(i)
            break #もう一度繰り返す

    else: #十の位も戻して、次に大きいやつをサーチしてくる
        exchange_list_1.clear()
        exchange_list_10.append(three_list[1])
        #戻す場所サーチ→戻し 削除
        for i in range(len(n_str)-2):
            if n_int_list[i]>=three_list[1]:
                n_int_list.insert(i, three_list[1])
                break
        else:
            n_int_list.append(three_list[1])
        three_list.pop() #three_list[1]
        for i in n_int_list:
            if i not in exchange_list_10:
                three_list.append(i) 
                n_int_list.remove(i)
                three_list.append(n_int_list[0])
                n_int_list.pop(0)
                break #もう一度、一の位を設定しなおして(元データベースの中から最小のものに設定&)繰り返す
        
        else: #100の位
            exchange_list_10.clear()
            exchange_list_100.append(three_list[0])
            for i in range(len(n_str)-1):
                if n_int_list[i]>=three_list[0]:
                    n_int_list.insert(i, three_list[0])
                    break
            else:
                n_int_list.append(three_list[0])
            three_list.pop()#three_listは空に
            for i in n_int_list:
                if i not in exchange_list_100:
                    three_list.append(i) 
                    n_int_list.remove(i)
                    three_list.append(n_int_list[0])
                    n_int_list.pop(0)
                    three_list.append(n_int_list[0])
                    n_int_list.pop(0)
                    break ##もう一度、十と一の位を設定しなおして(元データベースの中から最小のものに設定)繰り返す
            
            else: #下3桁全て試した状態
                print(120 - len(a))
                break

#まず降順にソートするか
#目安、10桁以上と仮定して進めよう
#→一桁目を記憶&popしてもとに戻す
#元データベースから、同じじゃない最小をpopして加える
#記憶に追加して、どれとも同じじゃない最小をpopして加える
#データベース探しても見つからない→2桁目を記憶して、2番目に小さい2桁目で頑張る→同様に3桁目も
0