CF1372E.Omkar and Last Floor

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Omkar is building a house. He wants to decide how to make the floor plan for the last floor.

Omkar's floor starts out as nn rows of mm zeros ( 1n,m1001 \le n,m \le 100 ). Every row is divided into intervals such that every 00 in the row is in exactly 11 interval. For every interval for every row, Omkar can change exactly one of the 00 s contained in that interval to a 11 . Omkar defines the quality of a floor as the sum of the squares of the sums of the values in each column, i. e. if the sum of the values in the ii -th column is qiq_i , then the quality of the floor is i=1mqi2\sum_{i = 1}^m q_i^2 .

Help Omkar find the maximum quality that the floor can have.

输入格式

The first line contains two integers, nn and mm ( 1n,m1001 \le n,m \le 100 ), which are the number of rows and number of columns, respectively.

You will then receive a description of the intervals in each row. For every row ii from 11 to nn : The first row contains a single integer kik_i ( 1kim1 \le k_i \le m ), which is the number of intervals on row ii . The jj -th of the next kik_i lines contains two integers li,jl_{i,j} and ri,jr_{i,j} , which are the left and right bound (both inclusive), respectively, of the jj -th interval of the ii -th row. It is guaranteed that all intervals other than the first interval will be directly after the interval before it. Formally, li,1=1l_{i,1} = 1 , li,jri,jl_{i,j} \leq r_{i,j} for all 1jki1 \le j \le k_i , ri,j1+1=li,jr_{i,j-1} + 1 = l_{i,j} for all 2jki2 \le j \le k_i , and ri,ki=mr_{i,k_i} = m .

输出格式

Output one integer, which is the maximum possible quality of an eligible floor plan.

输入输出样例

  • 输入#1

    4 5
    2
    1 2
    3 5
    2
    1 3
    4 5
    3
    1 1
    2 4
    5 5
    3
    1 1
    2 2
    3 5

    输出#1

    36

说明/提示

The given test case corresponds to the following diagram. Cells in the same row and have the same number are a part of the same interval.

The most optimal assignment is:

The sum of the 11 st column is 44 , the sum of the 22 nd column is 22 , the sum of the 33 rd and 44 th columns are 00 , and the sum of the 55 th column is 44 .

The quality of this floor plan is 42+22+02+02+42=364^2 + 2^2 + 0^2 + 0^2 + 4^2 = 36 . You can show that there is no floor plan with a higher quality.

首页