Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define Nmax 505
- using namespace std;
- ifstream in("tuburi.in");
- ofstream out("tuburi.out");
- int n,m,lm,p,r,k=0;
- int a[Nmax][Nmax],C[Nmax][Nmax];
- void citire()
- {
- in>>p>>n>>m;
- for (int i=1; i<=n; ++i)
- for (int j=1; j<=m; ++j)
- if(in>>a[i][j])
- ++k;
- for (int j=1; j<=m; ++j)
- if (a[1][j]%2==0)
- C[1][j]=j;
- }
- int lungime (int i,int j,int k)
- {
- int l=1,jj=0,g,col;
- if(j==0||j>m)
- return 0;
- do
- {
- g=0;
- col=C[i][j];
- if (a[i][j]&&a[i][j]<4)
- {
- if (a[i+1][j] && a[i+1][j]%2==0)
- {
- i++;
- l++;
- g=1;
- }
- }
- else
- switch(a[i][j])
- {
- case 4:
- if (a[i][j+1]==5 || a[i][j+1]==3)
- {
- jj=j;
- j++;
- l++;
- g=1;
- }
- break;
- case 5:
- if (jj==j-1)
- {
- if (a[i][j+1]==3 || a[i][j+1]==5)
- {
- jj=j;
- j++;
- l++;
- g=1;
- }
- }
- else
- {
- if (a[i][j-1]==1 || a[i][j-1]==5)
- {
- jj=j;
- j--;
- l++;
- g=1;
- }
- }
- break;
- case 6:
- if (a[i][j-1]==5 || a[i][j-1]==1)
- {
- jj=j;
- j--;
- l++;
- g=1;
- }
- }
- if(k==0)
- C[i][j]=col;
- }
- while (g);
- return l;
- }
- int main()
- {
- int j, l,lmv;
- citire();
- for (j=1; j<=m; j++)
- if (a[1][j]%2==0)
- {
- l=lungime(1,j,0);
- if (l>lm)
- lm=l;
- }
- lmv=lm;
- if(p==1)
- out<<lm<<'\n';
- else
- {
- int t,tc,c,aux,caz;
- in>>r;
- lm=0;
- for (j=1; j<=m; j++)
- {
- aux=a[r][j];
- for (tc=1; tc<=6; ++tc)
- {
- a[r][j]=tc;
- if(tc%2==0)
- if(r>1)
- l=lungime(1,C[r-1][j],r);
- else
- l=lungime(1,j,r);
- else if(tc==1)
- l=lungime(1,C[r][j+1],r);
- else if(tc==3)
- l=lungime(1,C[r][j-1],r);
- else
- {
- l=lungime(1,C[r][j-1],r);
- if (l>lm)
- {
- lm=l;
- c=j;
- t=tc;
- }
- l=lungime(1,C[r][j+1],r);
- }
- if (l>lm)
- {
- lm=l;
- c=j;
- t=tc;
- }
- }
- a[r][j]=aux;
- }
- out<<c<<' '<<t<<'\n';
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment