結果
問題 | No.1635 Let’s Sort Integers!! |
ユーザー |
👑 ![]() |
提出日時 | 2021-07-30 21:22:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 408 ms / 2,000 ms |
コード長 | 1,807 bytes |
コンパイル時間 | 202 ms |
コンパイル使用メモリ | 81,664 KB |
実行使用メモリ | 233,860 KB |
最終ジャッジ日時 | 2024-09-15 22:48:40 |
合計ジャッジ時間 | 23,094 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 77 |
ソースコード
""""""import sysfrom sys import stdinimport itertoolsfrom collections import dequeN,K = map(int,stdin.readline().split())OK = Kif K < N-1:print (-1)sys.exit()q = deque([i+1 for i in range(N)])l = [1]q.popleft()r = [N]q.pop()K -= N-1rem = []cnt = 0while q:if cnt % 2 == 0:x = q.popleft()if K-abs(r[-1]-x) >= 0:K -= abs(r[-1]-x)r.append(x)elif (K-abs(l[-1]-x) == 0):K -= abs(l[-1]-x)l.append(x)else:rem.append(x)if len(q) == 0:breakx = q.pop()if K-abs(l[-1]-x) >= 0:K -= abs(l[-1]-x)l.append(x)elif (K-abs(r[-1]-x) == 0):K -= abs(r[-1]-x)r.append(x)else:rem.append(x)else:x = q.pop()if K-abs(r[-1]-x) >= 0:K -= abs(r[-1]-x)r.append(x)elif (K-abs(l[-1]-x) == 0):K -= abs(l[-1]-x)l.append(x)else:rem.append(x)if len(q) == 0:breakx = q.popleft()if K-abs(l[-1]-x) >= 0:K -= abs(l[-1]-x)l.append(x)elif (K-abs(r[-1]-x) == 0):K -= abs(r[-1]-x)r.append(x)else:rem.append(x)cnt += 1if K != 0:print (-1)sys.exit()rem.sort()l.reverse()ans = l + rem + rprint (*ans)check = 0for i in range(N-1):check += abs(ans[i]-ans[i+1])assert check == OK"""p = itertools.permutations([i+1 for i in range(N)], N)maxi = 0for np in p:lis = list(np)now = 0for i in range(N-1):now += abs(lis[i+1]-lis[i])print (now,lis)maxi = max(now,maxi)print (maxi)"""