[ABC311G] One More Grid Task
Problem Statement
There is an $N \times M$ grid, where the square at the $i$-th row from the top and $j$-th column from the left has a non-negative integer $A_{i,j}$ written on it.
Let us choose a rectangular region $R$.
Formally, the region is chosen as follows.
- Choose integers $l_x, r_x, l_y, r_y$ such that $1 \le l_x \le r_x \le N, 1 \le l_y \le r_y \le M$.
- Then, square $(i,j)$ is in $R$ if and only if $l_x \le i \le r_x$ and $l_y \le j \le r_y$.
Find the maximum possible value of $f(R) = $ (the sum of integers written on the squares in $R$) $\times$ (the smallest integer written on a square in $R$).
Constraints
- All input values are integers.
- $1 \le N,M \le 300$
- $1 \le A_{i,j} \le 300$
这题有一万种做法。
枚举最小值 \(x\),现在要求一个权值和最大的矩阵,满足所有数的最小值不小于 \(x\)。
设 \(s_{i,j}\) 为 \((i,j)\) 往上最多有多少个数是不小于 \(x\) 的,然后对于某一行的某个区间,他往上能有多高取决于这个区间中所有数的最小值。
区间的最小值? 考虑单调栈求出这一行下一个和上一个比 \(v_{i,j}\) 小的区间,然后在这段区间之间的高度就取决于 \(v_{i,j}\) 的高度,二位前缀和统计即可。
#include<bits/stdc++.h>
using namespace std;
const int N=305;
typedef long long LL;
int n,m,st[N],s[N][N],ls[N],nx[N],tp,a[N][N],v[N][N];
LL p[N][N],ans;
LL ask(int ax,int ay,int bx,int by)
{
return p[bx][by]+p[ax-1][ay-1]-p[ax-1][by]-p[bx][ay-1];
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",a[i]+j),p[i][j]=p[i][j-1]+a[i][j];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
p[i][j]+=p[i-1][j];
for(int i=1;i<=300;i++)
{
for(int j=1;j<=n;j++)
{
for(int k=1;k<=m;k++)
{
if(a[j][k]>=i)
v[j][k]=v[j-1][k]+1;
else
v[j][k]=0;
}
}
for(int j=1;j<=n;j++)
{
for(int k=1;k<=m;k++)
ls[k]=0,nx[k]=m+1;
for(int k=1;k<=m;k++)
{
while(tp&&v[j][st[tp]]>v[j][k])
nx[st[tp--]]=k;
st[++tp]=k;
}
tp=0;
for(int k=m;k;k--)
{
while(tp&&v[j][st[tp]]>v[j][k])
ls[st[tp--]]=k;
st[++tp]=k;
}
for(int k=1;k<=m;k++)
ans=max(ans,1LL*i*ask(j-v[j][k]+1,ls[k]+1,j,nx[k]-1));
}
}
printf("%lld",ans);
}
[ABC311G] One More Grid Task的更多相关文章
- Libsvm:脚本(subset.py、grid.py、checkdata.py) | MATLAB/OCTAVE interface | Python interface
1.脚本 This directory includes some useful codes: 1. subset selection tools. (子集抽取工具) subset.py 2. par ...
- SZU-A22
Problem(A22):Party Judge InfoMemory Limit: 32768KBCase Time Limit: 10000MSTime Limit: 10000MSJudger: ...
- SVM应用
我在项目中应用的SVM库是国立台湾大学林智仁教授开发的一套开源软件,主要有LIBSVM与LIBLINEAR两个,LIBSVM是对非线性数据进行分类,大家也比较熟悉,LIBLINEAR是对线性数据进行分 ...
- PatentTips – GPU Saving and Restoring Thread Group Operating State
BACKGROUND OF THE INVENTION The present invention relates generally to single-instruction, multiple- ...
- 多线程之异步编程: 经典和最新的异步编程模型, IAsyncInfo 与 Task 相互转换
经典的异步编程模型(IAsyncResult) 最新的异步编程模型(async 和 await) 将 IAsyncInfo 转换成 Task 将 Task 转换成 IAsyncInfo 示例1.使用经 ...
- 多线程之任务: Task 基础, 多任务并行执行, 并行运算(Parallel)
Task - 基于线程池的任务(在 System.Threading.Tasks 命名空间下) 多 Task 的并行执行 Parallel - 并行计算(在 System.Threading.Task ...
- 重新想象 Windows 8 Store Apps (43) - 多线程之任务: Task 基础, 多任务并行执行, 并行运算(Parallel)
[源码下载] 重新想象 Windows 8 Store Apps (43) - 多线程之任务: Task 基础, 多任务并行执行, 并行运算(Parallel) 作者:webabcd 介绍重新想象 W ...
- 重新想象 Windows 8 Store Apps (44) - 多线程之异步编程: 经典和最新的异步编程模型, IAsyncInfo 与 Task 相互转换
[源码下载] 重新想象 Windows 8 Store Apps (44) - 多线程之异步编程: 经典和最新的异步编程模型, IAsyncInfo 与 Task 相互转换 作者:webabcd 介绍 ...
- hdu 1885 Key Task
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1885 Key Task Description The Czech Technical Univers ...
- Codeforces Round #249 (Div. 2) D. Special Grid 枚举
题目链接: http://codeforces.com/contest/435/problem/D D. Special Grid time limit per test:4 secondsmemor ...
随机推荐
- 【Azure App Service】为部署在App Service上的PHP应用开启JIT编译器
问题描述 在App Service for linux上创建一个PHP应用,通过 phpinfo() 查看PHP的扩展设置,发现JIT没有被开启, jit_buffer_size 大小为0. 那么,在 ...
- 3、Spring之入门案例
3.1.创建module 3.1.1.右击project,创建新module 3.1.2.选择maven 3.1.3.设置module名称和路径 3.1.4.module初始状态 3.1.5.配置打包 ...
- YShow性能测试平台搭建
ShowSlow安装 ShowSlow是一个YSlow性能数据收集平台,用于将收集的性能数据 ShowSlow是用php实现的,所以我们需要搭建一台服务器来接收YSlow数据 我搭建的环境是:ubun ...
- IOS苹果应用IPA一键签名工具(苹果重签名,企业签名,Windows平台,时间控制)
苹果应用IPA一键签名工具可以在windows平台对苹果应用IPA文件重新签名,无需MAC苹果电脑和配置XCODE开发环境,便可以直接对IPA文件进行签名,同时支持修改BundleID, 不受描述文件 ...
- Record - Nov. 21st, 2020 - Exam. REC & SOL
Craft Prob. 1 Desc. & Link. 有想法. printf( "nan" ); Prob.2 Desc. & Link. 没读懂 Prob. 3 ...
- oracle优化-分页查询的错误认识
对于分页查询,上一篇文章总结了实现分页查询的办法.同时给出等价写法,另外在执行计划角度验证SQL的等价性https://www.cnblogs.com/handhead/p/13856505.html ...
- Docker V24 及 Docker Compose V2 的安装及使用
前言 Docker 是一款流行的开源容器化平台,使用 Docker 可以有效地隔离应用程序和系统环境,使得应用程序在不同的环境中具有相同的行为 Docker Compose 是一个用于定义和管理多个 ...
- 为什么 CSS flex 布局中没有 `justify-items` 和 `justify-self`?
为什么 CSS flex 布局中没有 justify-items 和 justify-self? 为什么在 CSS flex 布局中存在 align-items 和 align-self,却没有 ju ...
- ts 终于搞懂TS中的泛型啦! | typescript 入门指南 04
大家好,我是王天~ 这篇文章是 ts入门指南系列中第四篇,主要讲解ts中的泛型应用,泛型在ts中是比较重要的概念,我花挺长时间才搞明白的,希望能帮助到大家 ~ ** ts 入门指南系列 ** Ts和J ...
- 从零用VitePress搭建博客教程(3) - VitePress页脚、标题logo、最后更新时间等相关细节配置
接上一节:从零用VitePress搭建博客教程(2) –VitePress默认首页和头部导航.左侧导航配置 五.默认主题相关细节配置 关于默认主题的标题,logo.页脚,最后更新时间等相关细节配置,我 ...