Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define NMAX 155
- using namespace std;
- ifstream fin("matrix_replace.in");
- ofstream fout("matrix_replace.out");
- short a[NMAX - 50][NMAX][NMAX];
- bool ap[NMAX];
- int n, k, Large_dim, UsedK;
- int main()
- {
- fin>>n>>k;
- for(int i=1;i<=n;++i)
- for(int j=1;j<=n;++j)
- {
- int x;
- fin>>x;
- ap[x]=1;
- a[x][i][j]=1;
- }
- for(int nr=0; nr<=100; ++nr)
- {
- if(ap[nr])
- {
- for(int i=1;i<=n;++i)
- for(int j=1;j<=n;++j)
- a[nr][i][j]=a[nr][i][j]+a[nr][i-1][j]+a[nr][i][j-1]-a[nr][i-1][j-1];
- for(int i=1;i<=n;++i)
- for(int j=1;j<=n;++j)
- {
- int curr=n-max(i,j)+1;
- for(int DimSQ=1;DimSQ<=curr;++DimSQ)
- {
- int SQ=DimSQ*DimSQ;
- int Sum=a[nr][i+DimSQ-1][j+DimSQ-1]-a[nr][i-1][j+DimSQ-1]-a[nr][i+DimSQ-1][j-1]+a[nr][i-1][j -1];
- if(SQ-Sum<=k)
- {
- if(DimSQ>Large_dim||(DimSQ==Large_dim&&SQ-Sum< UsedK))
- UsedK=SQ-Sum,Large_dim=DimSQ;
- }
- else
- DimSQ=200;
- }
- }
- }
- }
- fout<<Large_dim<<' '<<UsedK;
- return 0;
- }
Add Comment
Please, Sign In to add comment