题解:CF1372E Omkar and Last Floor
Swordmaker · · 题解
CF1372E Omkar and Last Floor
好题,太妙了。
题意:有一个
首先由初中知识可得
这意味着如果有一列上的
考虑区间 dp。
下设
设
每次转移时,我们钦定一列是闪耀的,当且仅当这一列存在某一行上该列所填的数为
因此,由于上文提到的性质,左右列满足条件的区间应当尽可能向闪耀的列合并,这样才能使平方之和更大。
所以我们可以列出转移式:
答案就是
预处理复杂度
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define i128 __int128
#ifdef __linux__
//#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define CK_TM cerr<<'\n'<<1.0*fabs(&ENDM-&STARTM)/(1024*1024)<<"MB"<<" "<<1.0*clock()/CLOCKS_PER_SEC*1000<<"ms"<<'\n';
char buf[1<<25],*p1,*p2;
#define getchar() ((p1==p2)&&(p2=(p1=buf)+fread(buf,1,1<<25,stdin))?EOF:*p1++)
#define vector basic_string
#define pq priority_queue
#define mkpr make_pair
#define pii pair<int,int>
#define pb push_back
#define umap unordered_map
#define uset unordered_set
#define vi vector<int>
#define sz(h) (int)h.size()
#define popc(x) __builtin_popcount(x)
bool STARTM;
constexpr double eps=1e-10;
constexpr int i_inf=1e9;
constexpr ll ll_inf=1e18;
namespace AyanamiRei{
inline int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9') {if(c=='-') f^=1;c=getchar();}
while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
return f?x:~x+1;
}
}namespace SoryuAsukaRangure{
inline void write(int x){
if(x<0) x=~x+1,putchar('-');
if(x>9) write(x/10);
return putchar(x%10^48),void();
}
}namespace AyanamiYue{
inline void spaceput(int x){
SoryuAsukaRangure::write(x);putchar(' ');
}
}namespace IkariYue{
inline void output(int x){
SoryuAsukaRangure::write(x);putchar('\n');
}
}namespace IkariShinji{
inline int max(int x,int y){
return x>y?x:y;
}
}namespace NagisaKaworu{
inline int min(int x,int y){
return x<y?x:y;
}
}namespace MariMakinamiIllustious{
inline double MAX(double x,double y){
return x-y>eps?x:y;
}
}namespace ShikinamiAsukaRangure{
inline double MIN(double x,double y){
return y-x>eps?x:y;
}
}
using namespace std;
using namespace AyanamiRei;
using namespace SoryuAsukaRangure;
using namespace AyanamiYue;
using namespace IkariYue;
using namespace IkariShinji;
using namespace NagisaKaworu;
using namespace MariMakinamiIllustious;
using namespace ShikinamiAsukaRangure;
constexpr int N=1e2+5;
constexpr int the_birthday_of_Asuka=20011204;
constexpr int the_birthday_of_Ayanami=20010330;
mt19937 Asuka(the_birthday_of_Asuka+time(0));
mt19937 Ayanami(the_birthday_of_Ayanami+time(0));
int n,m;
int dp[N][N],v[N][N][N];
#define S(x) (x*x)
bool ENDM;
signed main(){
n=read(),m=read();
for(int i=1;i<=n;i++){
int k;k=read();
while(k--){
int L,R;L=read(),R=read();
for(int l=1;l<=L;l++){
for(int r=R;r<=m;r++){
for(int p=L;p<=R;p++) v[l][r][p]++;
}
}
}
}
for(int i=1;i<=m;i++) dp[i][i]=S(v[i][i][i]);
for(int len=2;len<=m;len++){
for(int i=1;i<=m;i++){
int j=i+len-1;
if(j>m) break;
for(int k=i;k<=j;k++) dp[i][j]=max(dp[i][j],dp[i][k-1]+dp[k+1][j]+S(v[i][j][k]));
}
}
write(dp[1][m]);
CK_TM;
return 0;
}