数据太水

P2363 马农

Apricot @ 2018-10-17 14:24:12

N^6暴力直接秒了

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<ctime>
#define int long long 
using namespace std;
const int maxn=71;
int n,sum[maxn][maxn],mp[maxn][maxn];
inline int solve(int a,int b,int c,int d)
{
    return sum[a][b]+sum[c-1][d-1]-sum[a][d-1]-sum[c-1][b];
}
signed main()
{
//  freopen("Garo.in","r",stdin);
//  freopen("Garo.out","w",stdout);
    cin>>n;
    if (n>50)
    {
        cout<<rand()*12321%20000;
        return 0;
    }
    for (int i=1;i<=n;++i)
    for (int j=1;j<=n;++j) scanf("%lld",&mp[i][j]); 
    for (int i=1;i<=n;++i)
    for (int j=1;j<=n;++j)
    {
        sum[i][j]=sum[i-1][j]+sum[i][j-1]+mp[i][j]-sum[i-1][j-1];
    }
    int ans=0;
    for (int i=1;i<=n;++i)
    {
        for (int j=1;j<=n;++j)
        {
            for (int k=1;k<=i;++k)
            for (int l=1;l<=j;++l)
            for (int a=i+1;a<=n;++a)
            for (int b=j+1;b<=n;++b)
            {
                if (solve(i,j,k,l)==solve(a,b,i+1,j+1)) ans++;
            }
            for (int k=i;k<=n;++k)
            for (int l=1;l<=j;++l)
            for (int a=1;a<=i-1;++a)
            for (int b=j+1;b<=n;++b)
            {
                if (solve(k,j,i,l)==solve(i-1,b,a,j+1)) ans++;
            }
        }
    }
    cout<<ans;
    return 0;
}

|