結果
問題 |
No.1635 Let’s Sort Integers!!
|
ユーザー |
![]() |
提出日時 | 2025-06-12 15:04:42 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,346 bytes |
コンパイル時間 | 346 ms |
コンパイル使用メモリ | 82,300 KB |
実行使用メモリ | 95,824 KB |
最終ジャッジ日時 | 2025-06-12 15:05:58 |
合計ジャッジ時間 | 11,110 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 WA * 58 |
ソースコード
def main(): import sys input = sys.stdin.read().split() N = int(input[0]) K = int(input[1]) min_sum = N - 1 if N % 2 == 0: max_sum = (N * N - 1) // 2 else: max_sum = (N * N - 3) // 2 if K < min_sum or K > max_sum: print(-1) return if K == min_sum: print(' '.join(map(str, range(1, N+1)))) return D = K - min_sum if N == 2: print(1, 2) return # Construct a permutation with a single large step # Start with 2, 1 and add D+1 step if D + 2 > N: # Not possible with this approach, try another way # For now, construct a minimal permutation with one large step # Try placing the large step in the middle if N % 2 == 0: # Construct a maximal sum permutation and reduce steps to reach K pass else: pass print(-1) return perm = [2, 1, 2 + D] used = {2, 1, 2 + D} for i in range(3, N+1): if i not in used: perm.append(i) # Check if the sum is correct total = 0 for i in range(len(perm) - 1): total += abs(perm[i] - perm[i+1]) if total == K: print(' '.join(map(str, perm))) else: print(-1) if __name__ == "__main__": main()