結果
| 問題 |
No.1635 Let’s Sort Integers!!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-12 18:00:26 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,806 bytes |
| コンパイル時間 | 647 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 89,604 KB |
| 最終ジャッジ日時 | 2025-08-12 18:01:21 |
| 合計ジャッジ時間 | 52,087 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 62 TLE * 15 |
ソースコード
"""
"""
import sys
from sys import stdin
import itertools
from collections import deque
N,K = map(int,stdin.readline().split())
OK = K
if 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-1
rem = []
cnt = 0
while 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:
break
x = 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:
break
x = 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 += 1
if K != 0:
print (-1)
sys.exit()
rem.sort()
l.reverse()
ans = l + rem + r
print (*ans)
check = 0
for 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 = 0
for np in p:
lis = list(np)
now = 0
for i in range(N-1):
now += abs(lis[i+1]-lis[i])
print (now,lis)
maxi = max(now,maxi)
print (maxi)
"""