a53

tuburi

a53
May 3rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define Nmax 505
  3. using namespace std;
  4.  
  5. ifstream in("tuburi.in");
  6. ofstream out("tuburi.out");
  7.  
  8. int n,m,lm,p,r,k=0;
  9. int a[Nmax][Nmax],C[Nmax][Nmax];
  10.  
  11. void citire()
  12. {
  13. in>>p>>n>>m;
  14. for (int i=1; i<=n; ++i)
  15. for (int j=1; j<=m; ++j)
  16. if(in>>a[i][j])
  17. ++k;
  18. for (int j=1; j<=m; ++j)
  19. if (a[1][j]%2==0)
  20. C[1][j]=j;
  21. }
  22.  
  23. int lungime (int i,int j,int k)
  24. {
  25. int l=1,jj=0,g,col;
  26. if(j==0||j>m)
  27. return 0;
  28. do
  29. {
  30. g=0;
  31. col=C[i][j];
  32. if (a[i][j]&&a[i][j]<4)
  33. {
  34. if (a[i+1][j] && a[i+1][j]%2==0)
  35. {
  36. i++;
  37. l++;
  38. g=1;
  39. }
  40. }
  41. else
  42. switch(a[i][j])
  43. {
  44. case 4:
  45. if (a[i][j+1]==5 || a[i][j+1]==3)
  46. {
  47. jj=j;
  48. j++;
  49. l++;
  50. g=1;
  51. }
  52. break;
  53. case 5:
  54. if (jj==j-1)
  55. {
  56. if (a[i][j+1]==3 || a[i][j+1]==5)
  57. {
  58. jj=j;
  59. j++;
  60. l++;
  61. g=1;
  62. }
  63. }
  64. else
  65. {
  66. if (a[i][j-1]==1 || a[i][j-1]==5)
  67. {
  68. jj=j;
  69. j--;
  70. l++;
  71. g=1;
  72. }
  73. }
  74. break;
  75. case 6:
  76. if (a[i][j-1]==5 || a[i][j-1]==1)
  77. {
  78. jj=j;
  79. j--;
  80. l++;
  81. g=1;
  82. }
  83. }
  84. if(k==0)
  85. C[i][j]=col;
  86. }
  87. while (g);
  88. return l;
  89. }
  90.  
  91. int main()
  92. {
  93. int j, l,lmv;
  94. citire();
  95. for (j=1; j<=m; j++)
  96. if (a[1][j]%2==0)
  97. {
  98. l=lungime(1,j,0);
  99. if (l>lm)
  100. lm=l;
  101. }
  102. lmv=lm;
  103. if(p==1)
  104. out<<lm<<'\n';
  105. else
  106. {
  107. int t,tc,c,aux,caz;
  108. in>>r;
  109. lm=0;
  110. for (j=1; j<=m; j++)
  111. {
  112. aux=a[r][j];
  113. for (tc=1; tc<=6; ++tc)
  114. {
  115. a[r][j]=tc;
  116. if(tc%2==0)
  117. if(r>1)
  118. l=lungime(1,C[r-1][j],r);
  119. else
  120. l=lungime(1,j,r);
  121. else if(tc==1)
  122. l=lungime(1,C[r][j+1],r);
  123. else if(tc==3)
  124. l=lungime(1,C[r][j-1],r);
  125. else
  126. {
  127. l=lungime(1,C[r][j-1],r);
  128. if (l>lm)
  129. {
  130. lm=l;
  131. c=j;
  132. t=tc;
  133. }
  134. l=lungime(1,C[r][j+1],r);
  135. }
  136. if (l>lm)
  137. {
  138. lm=l;
  139. c=j;
  140. t=tc;
  141. }
  142. }
  143. a[r][j]=aux;
  144. }
  145. out<<c<<' '<<t<<'\n';
  146. }
  147. return 0;
  148. }
Add Comment
Please, Sign In to add comment