1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ARC176 A - 01 Matrix Again

Last updated at Posted at 2024-04-22
1 / 8
  • $N$ 行 $N$ 列の白いマス目がある
  • うち $M$ マスは黒く塗られている
    image.png

  • 追加で何マスか黒く塗って、
    どの行も列も黒マス $M$ 個にする

image.png


解き方(一例)


  • ナナメの直線を足すと、どの行も列も $1$ マス増える
    image.png

  • すでにある黒マスから直線を引いてみる
    image.png

  • まだ足りない場合は、適当に
    白マスを選んで直線を引く
    image.png

計算量

  • 線を $1$ 本引くのに $O(N)$ かかる
  • 線は $M$ 本ある
  • → $O(MN)$ で解くことができた
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?