#P7315. [COCI 2018/2019 #3] Sajam

[COCI 2018/2019 #3] Sajam

Description

Each area consists of NN rows, and each row has NN stalls. There are 33 types of operations to change the lighting state (changing a lit lamp to unlit, and vice versa):

  1. LEET selects an entire row and automatically toggles the lighting state of all lamps in that row.
  2. LEET selects an entire column and automatically toggles the lighting state of all lamps in that column.
  3. Milo selects one stall and manually toggles the lighting state of the lamp at that stall.

Is there a way for Milo to turn off all lamps, using operation 3 at most KK times?

Input Format

The first line contains integers N,KN, K.

The next NN lines each contain NN characters x or o, representing the lighting state of the lamps at the corresponding stalls in the Christmas fair. Here, x means unlit, and o means lit.

Output Format

If there is a plan that satisfies the requirement, output DA; otherwise output NE.

2 0
ox
ox
DA
3 1
ooo
xoo
oox
NE
4 2
oxxo
xxox
oxoo
oxxo
DA

Hint

Explanation for Sample 3

One feasible plan is:

  • Perform operation 22, selecting column 11.
  • Perform operation 33, selecting (2,2)(2,2).
  • Perform operation 11, selecting row 22.
  • Perform operation 22, selecting column 44.
  • Perform operation 33, selecting (3,3)(3,3).

Constraints

For 1515 points, K=0K = 0.

For another 1515 points, N100N \le 100.

For another 3030 points, K<N2K \lt \dfrac{N}{2}.

For 100%100\% of the testdata, 1N10001 \le N \le 1000, 0KN0 \le K \le N.

Notes

The scoring of this problem follows the original COCI settings, with a full score of 9090. Only 1818 test points with different difficulties are selected for evaluation here.

Translated from COCI2018-2019 CONTEST #3 T3 Sajam.

Translated by ChatGPT 5