Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int h[5][2005];
- int sp[2005];
- int main()
- {
- freopen("banda.in","r",stdin);
- freopen("banda.out","w",stdout);
- int n,x;
- scanf("%d",&n);
- for(int i=1;i<=n;++i)
- {
- for(int j=1;j<=n;++j)
- {
- scanf("%d ",&x);
- h[1][i]+=x;
- h[2][j]+=x;
- h[4][i+j-1]+=x;
- h[3][i+n-j]+=x;
- }
- }
- int maxx=INT_MIN,rang=0,segv=0;
- int cnt=0;
- for(int i=1;i<=n;++i)
- {
- if(h[1][i]!=n)
- {
- if(maxx<cnt*n&&cnt>1)
- {
- maxx=cnt*n;
- rang=1;
- segv=cnt;
- }
- cnt=0;
- continue;
- }
- cnt++;
- }
- if(maxx<cnt*n&&cnt>1)
- {
- maxx=cnt*n;
- rang=1;
- segv=cnt;
- }
- cnt=0;
- for(int i=1;i<=n;++i)
- {
- if(h[2][i]!=n)
- {
- if(maxx<cnt*n&&cnt>1)
- {
- maxx=cnt*n;
- rang=2;
- segv=cnt;
- }
- cnt=0;
- continue;
- }
- cnt++;
- }
- if(maxx<cnt*n&&cnt>1)
- {
- maxx=cnt*n;
- rang=2;
- segv=cnt;
- }
- cnt=0;
- for(int i=1;i<=2*n-1;++i)
- {
- sp[i]=sp[i-1]+(i<=n ? i : 2*n-i);
- }
- int st=1,dr=1;
- for(dr=1;dr<=2*n-1;++dr)
- {
- if(h[4][dr]!=(dr<=n ? dr: 2*n-dr))
- {
- if(maxx<sp[dr-1]-sp[st-1]&&h[4][st]==(st<=n ? st : 2*n-st)&&dr-st>1)
- {
- maxx=sp[dr-1]-sp[st-1];
- rang=4;
- segv=dr-st;
- }
- st=dr+1;
- }
- //dr++;
- }
- if(maxx<sp[dr-1]-sp[st-1]&&h[4][st]==(st<=n ? st : 2*n-st)&&dr-st>1)
- {
- maxx=sp[dr-1]-sp[st-1];
- rang=4;
- segv=dr-st;
- }
- st=dr;
- st=1,dr=1;
- for(dr=1;dr<=2*n-1;++dr)
- {
- if(h[3][dr]!=(dr<=n ? dr: 2*n-dr))
- {
- if(maxx<sp[dr-1]-sp[st-1]&&h[3][st]==(st<=n ? st : 2*n-st)&&dr-st>1)
- {
- maxx=sp[dr-1]-sp[st-1];
- rang=3;
- segv=dr-st;
- }
- st=dr+1;
- }
- //dr++;
- }
- if(maxx<sp[dr-1]-sp[st-1]&&h[3][st]==(st<=n ? st : 2*n-st)&&dr-st>1)
- {
- maxx=sp[dr-1]-sp[st-1];
- rang=3;
- segv=dr-st;
- }
- st=dr;
- printf("%d\n%d\n%d\n",rang,segv,maxx);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement