CF1372E.Omkar and Last Floor
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
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 n rows of m zeros (1≤n,m≤100). Every row is divided into intervals such that every 0 in the row is in exactly 1 interval. For every interval for every row, Omkar can change exactly one of the 0s contained in that interval to a 1. 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 i-th column is qi, then the quality of the floor is ∑i=1mqi2.
Help Omkar find the maximum quality that the floor can have.
奥马尔正在建造一座房子,他需要决定顶层的平面图设计。
奥马尔的楼层初始为 n 行 m 列的零矩阵(1≤n,m≤100)。每一行被划分为若干区间,使得该行中的每个 0 恰好属于一个区间。对于每一行的每一个区间,奥马尔可以将该区间中恰好一个 0 改为 1。奥马尔将楼层的“质量”定义为:各列数值之和的平方的总和;即若第 i 列的数值之和为 qi,则楼层的质量为 ∑i=1mqi2。
请帮助奥马尔求出楼层所能达到的最大质量。
输入格式
The first line contains two integers, n and m (1≤n,m≤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 i from 1 to n: The first row contains a single integer ki (1≤ki≤m), which is the number of intervals on row i. The j-th of the next ki lines contains two integers li,j and ri,j, which are the left and right bound (both inclusive), respectively, of the j-th interval of the i-th row. It is guaranteed that all intervals other than the first interval will be directly after the interval before it. Formally, li,1=1, li,j≤ri,j for all 1≤j≤ki, ri,j−1+1=li,j for all 2≤j≤ki, and ri,ki=m.
第一行包含两个整数 n 和 m(1≤n,m≤100),分别表示行数和列数。
随后,你将收到每一行中区间的描述。对于从 1 到 n 的每一行 i:
第一行包含一个整数 ki(1≤ki≤m),表示第 i 行中区间的数量。
接下来的 ki 行中,第 j 行包含两个整数 li,j 和 ri,j,分别表示第 i 行中第 j 个区间的左边界和右边界(均包含端点)。
保证除第一个区间外,其余每个区间都紧接在前一个区间之后。形式化地,满足:
li,1=1,
对所有 1≤j≤ki,有 li,j≤ri,j,
对所有 2≤j≤ki,有 ri,j−1+1=li,j,
且 ri,ki=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 1st column is 4, the sum of the 2nd column is 2, the sum of the 3rd and 4th columns are 0, and the sum of the 5th column is 4.
The quality of this floor plan is 42+22+02+02+42=36. You can show that there is no floor plan with a higher quality.
给定的测试用例对应于以下示意图。同一行中编号相同的单元格属于同一区间。

最优的分配方案如下:

第 1 列的和为 4,第 2 列的和为 2,第 3 列和第 4 列的和均为 0,第 5 列的和为 4。
该平面布局的质量为 42+22+02+02+42=36。可以证明,不存在质量更高的平面布局。
输入解题思路,AI测评打分。不知道怎么写?