結果
| 問題 |
No.1635 Let’s Sort Integers!!
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 20:04:15 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,464 bytes |
| コンパイル時間 | 357 ms |
| コンパイル使用メモリ | 81,796 KB |
| 実行使用メモリ | 132,168 KB |
| 最終ジャッジ日時 | 2025-06-12 20:09:41 |
| 合計ジャッジ時間 | 13,383 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 58 |
ソースコード
def main():
import sys
N, K = map(int, sys.stdin.readline().split())
S_min = N - 1
S_max = (N * (N - 1)) // 2
if K < S_min or K > S_max:
print(-1)
return
if K == S_min:
print(' '.join(map(str, range(1, N + 1))))
return
elif K == S_max:
# Construct the maximal permutation
result = []
left = 1
right = N
while left <= right:
if left == right:
result.append(left)
break
result.append(left)
result.append(right)
left += 1
right -= 1
print(' '.join(map(str, result)))
return
else:
# Construct a permutation starting with 2, 1, N, 3, 4, ..., N-1
# Check if this permutation's sum is K
if N == 2:
print('2 1')
return
else:
# Create the permutation
permutation = [2, 1, N]
current = 3
while current < N:
permutation.append(current)
current += 1
# Now check the sum
total = 0
for i in range(len(permutation)-1):
total += abs(permutation[i] - permutation[i+1])
if total == K:
print(' '.join(map(str, permutation)))
return
else:
print(-1)
return
if __name__ == "__main__":
main()
gew1fw