結果
| 問題 | 
                            No.630 門松グラフ
                             | 
                    
| コンテスト | |
| ユーザー | 
                             wajima_wataru
                         | 
                    
| 提出日時 | 2018-01-05 22:48:17 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 266 ms / 1,500 ms | 
| コード長 | 830 bytes | 
| コンパイル時間 | 93 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 15,104 KB | 
| 最終ジャッジ日時 | 2024-12-23 07:03:37 | 
| 合計ジャッジ時間 | 5,632 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 32 | 
ソースコード
import math
N, M = map(int, input().split())
if M < N - 1:
    print('NO')
    exit()    
if N % 2 == 0:
    if M > (N // 2) ** 2:
        print('NO')
        exit()
else:
    if M > (N // 2) * (N // 2 + 1):
        print('NO')
        exit()
print('YES')
for i in range(N):
    print(i + 1, end=' ')
print()
small = list(range(1, math.ceil(N / 2) + 1))
big = list(range(math.ceil(N / 2) + 1, N + 1))
count = 0
flg = True
s = 0
b = 0
while count < M:
    if flg:
        for n in big[b:]:
            print(str(small[s]) + ' ' + str(n))
            count += 1
            if count >= M:
                exit()
        s += 1
    else:
        for n in small[s:]:
            print(str(big[b]) + ' ' + str(n))
            count += 1
            if count >= M:
                exit()
        b += 1             
    flg = not(flg)
            
            
            
        
            
wajima_wataru