結果

問題 No.942 プレゼント配り
ユーザー prd_xxxprd_xxx
提出日時 2019-12-05 15:04:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 17,748 KB
最終ジャッジ日時 2023-08-22 20:49:25
合計ジャッジ時間 3,020 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,308 KB
testcase_01 AC 108 ms
17,652 KB
testcase_02 AC 15 ms
8,164 KB
testcase_03 AC 16 ms
8,104 KB
testcase_04 AC 150 ms
16,876 KB
testcase_05 AC 109 ms
17,748 KB
testcase_06 AC 15 ms
8,272 KB
testcase_07 AC 15 ms
8,240 KB
testcase_08 AC 112 ms
14,468 KB
testcase_09 AC 122 ms
15,248 KB
testcase_10 AC 16 ms
8,268 KB
testcase_11 AC 16 ms
8,320 KB
testcase_12 AC 16 ms
8,232 KB
testcase_13 AC 16 ms
8,204 KB
testcase_14 AC 141 ms
15,764 KB
testcase_15 AC 85 ms
12,956 KB
testcase_16 AC 99 ms
13,728 KB
testcase_17 AC 97 ms
13,416 KB
testcase_18 AC 16 ms
8,188 KB
testcase_19 AC 16 ms
8,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K = map(int,input().split())
if K==1:
    print('Yes')
    print(*list(range(1,N+1)))
    exit()
sum_all = N*(N+1)//2
if sum_all % K:
    print('No')
    exit()
A= N//K
if A==1:
    print('No')
    exit()
print('Yes')

ans = [[] for i in range(K)]

a = N
till = 2*K if A%2 else 0
forward = True
while a > till:
    if forward:
        for i in range(K):
            ans[i].append(a)
            a -= 1
    else:
        for i in range(K-1,-1,-1):
            ans[i].append(a)
            a -= 1
    forward = not forward

if A%2:
    m = (K+1)//2
    for i in range(m):
        ans[i].append(2*i + 1)
    for i in range(m,K):
        ans[i].append(2*(i-m+1))
    a = K+1
    for i in range(m-1,-1,-1):
        ans[i].append(a)
        a += 1
    for i in range(K-1,m-1,-1):
        ans[i].append(a)
        a += 1

for row in ans:
    print(*row)
0