CF873C.Strange Game On Matrix

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Ivan is playing a strange game.

He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows:

  1. Initially Ivan's score is 0;
  2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that a__i, j = 1). If there are no 1's in the column, this column is skipped;
  3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score.

Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score.

伊万正在玩一个奇怪的游戏。

他有一个 nn 行 mm 列的矩阵 aa,其中每个元素均为 00 或 11。行和列均从 11 开始编号。伊万可以将矩阵中任意多个 11 替换为 00。之后,他的游戏得分将按如下方式计算:

  1. 最初伊万的得分为 00;
  2. 对每一列,伊万将找出该列中最靠上的 11(即:若当前列为 jj,则他将找出满足 ai,j=1a_{i,j} = 1 的最小行号 ii)。若该列中没有 11,则跳过该列;
  3. 伊万将查看该列中从上一步找到的元素开始的接下来 min⁡(k, n−i+1)\min(k,\, n - i + 1) 个元素(含该元素本身),并统计其中 11 的个数;该数目将被加到他的总得分中。

显然,伊万希望在此奇怪游戏中获得尽可能高的得分。同时,他也不想修改太多元素,因此他希望将尽可能少的 11 替换为 00。请你帮他确定:他所能获得的最高可能得分,以及为达成该得分所需的最少替换次数。

输入格式

The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100).

Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1.

第一行包含三个整数 nn、mm 和 kk(满足 1 ≤ k ≤ n ≤ 1001 \le k \le n \le 100,1 ≤ m ≤ 1001 \le m \le 100)。

接下来有 nn 行,其中第 ii 行包含 mm 个整数——即矩阵 aa 的第 ii 行的元素。每个数均为 00 或 11。

输出格式

Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score.

输出两个数字:伊万能够获得的最高可能得分,以及为达到该得分所需的最少替换次数。

输入输出样例

  • 输入#1

    4 3 2
    0 1 0
    1 0 1
    0 1 0
    1 1 1

    输出#1

    4 1
  • 输入#2

    3 2 1
    1 0
    0 1
    0 0

    输出#2

    2 0

说明/提示

In the first example Ivan will replace the element _a_1, 2.

在第一个例子中,伊万将替换元素 a1,2a_{1,2}。

输入解题思路,AI测评打分。不知道怎么写?

首页