結果

問題 No.2112 All 2x2 are Equal
ユーザー とりゐとりゐ
提出日時 2022-10-28 22:50:23
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 334 ms / 2,000 ms
コード長 1,547 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 94,648 KB
最終ジャッジ日時 2023-09-20 06:00:26
合計ジャッジ時間 12,624 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,052 KB
testcase_01 AC 73 ms
71,512 KB
testcase_02 AC 108 ms
77,784 KB
testcase_03 AC 97 ms
77,656 KB
testcase_04 AC 197 ms
84,472 KB
testcase_05 AC 209 ms
82,152 KB
testcase_06 AC 294 ms
86,012 KB
testcase_07 AC 160 ms
80,220 KB
testcase_08 AC 256 ms
84,240 KB
testcase_09 AC 109 ms
78,196 KB
testcase_10 AC 172 ms
80,620 KB
testcase_11 AC 146 ms
79,392 KB
testcase_12 AC 170 ms
82,192 KB
testcase_13 AC 272 ms
84,816 KB
testcase_14 AC 107 ms
78,032 KB
testcase_15 AC 241 ms
87,224 KB
testcase_16 AC 88 ms
76,828 KB
testcase_17 AC 251 ms
84,028 KB
testcase_18 AC 104 ms
77,884 KB
testcase_19 AC 111 ms
78,156 KB
testcase_20 AC 108 ms
78,068 KB
testcase_21 AC 274 ms
89,480 KB
testcase_22 AC 106 ms
78,080 KB
testcase_23 AC 102 ms
77,940 KB
testcase_24 AC 121 ms
78,104 KB
testcase_25 AC 126 ms
78,672 KB
testcase_26 AC 117 ms
78,188 KB
testcase_27 AC 145 ms
80,352 KB
testcase_28 AC 211 ms
84,720 KB
testcase_29 AC 121 ms
78,348 KB
testcase_30 AC 160 ms
80,136 KB
testcase_31 AC 221 ms
82,628 KB
testcase_32 AC 310 ms
86,488 KB
testcase_33 AC 302 ms
86,460 KB
testcase_34 AC 334 ms
94,648 KB
testcase_35 AC 304 ms
86,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def calc(h,w):
  # w is odd
  ans=[[0]*w for i in range(h)]
  for i in range(h):
    for j in range(w):
      if i%2==0:
        ans[i][j]=j+1
      else:
        ans[i][j]=w-j
  
  for i in range((h+1)//2):
    if 2*i+1!=h:
      i1=2*i
      i2=i1+1
      for j in range(w):
        if j%2==0:
          ans[i1][j]+=w*i
          ans[i2][j]+=w*(h-1-i)
        else:
          ans[i2][j]+=w*i
          ans[i1][j]+=w*(h-1-i)  
    else:
      for j in range(w):
        ans[-1][j]+=w*(h//2)
  return ans

def calc2(h,w):
  # w and h are even
  ans=[[0]*w for i in range(h)]
  for i in range(h):
    for j in range(w):
      if i%2==0:
        ans[i][j]=j+1
      else:
        ans[i][j]=w-j
  
  for i in range(h//2):
    i1=2*i
    i2=2*i+1
    for j in range(w//2):
      if j%2==0:
        ans[i1][j]+=w*i
        ans[i2][j]+=w*(h-1-i)
      else:
        ans[i2][j]+=w*i
        ans[i1][j]+=w*(h-1-i)
    for j in range(w//2,w):
      if j%2==0:
        ans[h-1-i1][j]+=w*i
        ans[h-1-i2][j]+=w*(h-1-i)
      else:
        ans[h-1-i2][j]+=w*i
        ans[h-1-i1][j]+=w*(h-1-i)
  
  return ans

h,w=map(int,input().split())
if w%2==1:
  ans=calc(h,w)
  
elif h%2==1:
  tmp=calc(w,h)
  ans=[[0]*w for i in range(h)]
  for i in range(h):
    for j in range(w):
      ans[i][j]=tmp[j][i]

else:
  ans=calc2(h,w)

print('Yes')
for i in ans:
  print(*i)

s=set()
for i in range(h-1):
  for j in range(w-1):
    tmp=0
    for di in range(2):
      for dj in range(2):
        tmp+=ans[i+di][j+dj]
    s.add(tmp)

if len(s)!=1:
  raise Exception
0