結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー kozykozy
提出日時 2021-02-19 21:59:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,253 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 11,036 KB
実行使用メモリ 29,920 KB
最終ジャッジ日時 2023-10-15 01:30:23
合計ジャッジ時間 29,561 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,736 KB
testcase_01 AC 16 ms
8,540 KB
testcase_02 AC 16 ms
8,612 KB
testcase_03 AC 17 ms
8,732 KB
testcase_04 AC 16 ms
8,580 KB
testcase_05 AC 16 ms
8,616 KB
testcase_06 AC 215 ms
19,712 KB
testcase_07 WA -
testcase_08 AC 216 ms
24,800 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 211 ms
19,584 KB
testcase_12 WA -
testcase_13 AC 165 ms
22,212 KB
testcase_14 AC 173 ms
22,060 KB
testcase_15 WA -
testcase_16 AC 183 ms
29,872 KB
testcase_17 AC 184 ms
29,768 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 172 ms
22,348 KB
testcase_22 AC 171 ms
22,296 KB
testcase_23 WA -
testcase_24 AC 209 ms
19,724 KB
testcase_25 WA -
testcase_26 AC 221 ms
24,748 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 215 ms
20,016 KB
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

W,H,X=map(int,input().split())
L=[[0 for i in range(W)] for j in range(H)]
if H<=2 and W<=2:
  if 9*H*W<X:
    print(-1)
    exit()
  else:
    for i in range(H):
      for j in range(W):
        if X<=9:
          L[i][j]=X
          X=0
          break
        else:
          L[i][j]=9
          X-=9
  for i in range(H):
    A=[str(i) for i in L[i]]
    print("".join(A))
  exit()
if H==1:
  if X>18:
    print(-1)
    exit()
  if X<=9:
    if W%3==0:
      print(("0"+str(X)+"0")*(X//3))
      exit()
    else:
      L=str()
      for i in range(W):
        if i%3==0:
          L+=str(X)
        else:
          L+="0"
      print(L)
      exit()
  else:
    if W%3!=2:
      print(-1)
      exit()
    else:
      S=str()
      for i in range(W):
        if i%3==0:
          S+="9"
        elif i%3==1:
          S+=str(X-9)
        else:
          S+="0"
      print(S)
      exit()
  exit()
if W==1:
  H,W=W,H
  if X>18:
    print(-1)
    exit()
  if X<=9:
    if W%3==0:
      for i in range(W):
        if i%3==1:
          print(str(X))
        else:
          print("0")
      exit()
    else:
      for i in range(W):
        if i%3==0:
          print(str(X))
        else:
          print("0")
      exit()
  else:
    if W%3!=2:
      print(-1)
      exit()
    else:
      S=str()
      for i in range(W):
        if i%3==0:
          print("9")
        elif i%3==1:
          print(str(X-9))
        else:
          print("0")
      exit()
  exit()
  
L=[[-1 for i in range(W)] for j in range(H)]
for i in range(H):
  if i%3==2:
    L[i]=["0"]*W
if H%3==1:
  for i in range(H):
    if i%3==1:
      L[i]=["0"]*W
if H%3==0:
  for i in range(H):
    if i%3==0:
      L[i]=["0"]*W
if W%3==1:
  for i in range(H):
    for j in range(W):
      if j%3==1:
        L[i][j]="0"
if W%3==0:
  for i in range(H):
    for j in range(W):
      if j%3==0:
        L[i][j]="0"
R=[[-1 for i in range(3)] for j in range(3)]
for i in range(3):
  for j in range(3):
    if i>=H or j>=W:
      continue
    R[i][j]=L[i][j]
    if L[i][j]!="0":
      if X<=9:
        R[i][j]=X
        X=0
      else:
        R[i][j]=9
        X-=9
if X!=0:
  print(-1)
  exit()
for i in range(H):
  for j in range(W):
    L[i][j]=str(R[i%3][j%3])
  print("".join(L[i]))
0