N^4为什么超时了,求改,玄关
  • 板块P1369 矩形
  • 楼主D5ysfzhw
  • 当前回复2
  • 已保存回复2
  • 发布时间2025/7/28 14:25
  • 上次更新2025/7/28 17:01:48
查看原帖
N^4为什么超时了,求改,玄关
1219162
D5ysfzhw楼主2025/7/28 14:25

n4n^4

#include<bits/stdc++.h>
using namespace std;
int a[105][105],n,sum[105][105],ans=-(1<<30);
int read(){
    int ret=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-f,ch=getchar();}
    while( isdigit(ch))ret=(ret<<3)+(ret<<1)+(ch&15),ch=getchar();
    return ret*f; 
}
int main(){
    n=read();
    for(int i=1;i<=n;i++)a[read()][read()]=1;
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j];
        }
    }
    for(int x=1;x<=99;x++){
        for(int x1=x+1;x1<=100;x1++){
            for(int y=1;y<=99;y++){
                for(int y1=y+1;y1<=100;y1++){
                    int s1=sum[x1][y1]-sum[x-1][y1]-sum[x1][y-1]+sum[x-1][y-1];
                    int s2=sum[x1-1][y1-1]-sum[x][y1-1]-sum[x1-1][y]+sum[x][y];
                    ans=max(ans,s1-s2);
                }
            }
        }
    }
    cout<<ans;
}

求改 回复不了私信我

2025/7/28 14:25
加载中...