結果
| 問題 |
No.2593 Reorder and Mod 120
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-30 23:34:34 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 4,195 bytes |
| コンパイル時間 | 159 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-09-27 16:55:43 |
| 合計ジャッジ時間 | 1,555 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 5 RE * 21 |
ソースコード
#最大で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桁目も