結果
| 問題 |
No.1635 Let’s Sort Integers!!
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 19:09:54 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,324 bytes |
| コンパイル時間 | 398 ms |
| コンパイル使用メモリ | 82,200 KB |
| 実行使用メモリ | 153,544 KB |
| 最終ジャッジ日時 | 2025-06-12 19:10:13 |
| 合計ジャッジ時間 | 15,654 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 WA * 61 |
ソースコード
def main():
import sys
input = sys.stdin.read().split()
N = int(input[0])
K = int(input[1])
if N == 1:
print(1 if K == 0 else -1)
return
# Compute S_max
if N % 2 == 0:
S_max = (N * N) // 2 - 1
else:
S_max = (N * N - 3) // 2
min_sum = N - 1
if K < min_sum or K > S_max or (S_max - K) % 2 != 0:
print(-1)
return
# Construct maximum permutation
if N % 2 == 0:
mid = N // 2
p = []
low = mid
high = N
for _ in range(mid):
p.append(low)
p.append(high)
low -= 1
high -= 1
else:
mid = (N + 1) // 2
p = [mid]
high = N
low = mid - 1
direction = 1 # 1 for high, 0 for low
for _ in range(N - 1):
if direction == 1:
p.append(high)
high -= 1
else:
p.append(low)
low -= 1
direction ^= 1
x = (S_max - K) // 2
# Perform x swaps to reduce sum by 2 each
for i in range(x):
pos = 2 * i + 1
if pos + 1 >= len(p):
break
p[pos], p[pos + 1] = p[pos + 1], p[pos]
print(' '.join(map(str, p)))
if __name__ == "__main__":
main()
gew1fw