Advertisement
a53

soricel

a53
Apr 4th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. ifstream f("soricel.in");
  7. ofstream g("soricel.out");
  8.  
  9. int a[202][202],v[50001],dif[50001],c,n,m,k,i,j,x,t,maxim,r, lungime, zi,nr,smax,s;
  10.  
  11. int main()
  12. {
  13. f>>c;
  14. f>>n>>m>>k;
  15. for(i=1; i<=n; i++)
  16. for(j=1; j<=m; j++)
  17. f>>a[i][j];
  18. maxim=1;
  19. for(i=1; i<=n; i++)
  20. {
  21. if(i%2==1)
  22. for(j=1; j<=m; j++)
  23. {
  24. x++;
  25. if(a[i][j]!=0)
  26. {
  27. if(a[i][j]==1)
  28. {
  29. dif[x]=0;
  30. v[x]=0;
  31. }
  32. else if(sqrt(a[i][j])==int(sqrt(a[i][j])))
  33. {
  34. dif[x]=a[i][j]-(sqrt(a[i][j])-1)*(sqrt(a[i][j])-1);
  35. v[x]=(sqrt(a[i][j])-1)*(sqrt(a[i][j])-1);
  36. }
  37. else
  38. {
  39. dif[x]=a[i][j]-(int(sqrt(a[i][j])))*(int(sqrt(a[i][j])));
  40. v[x]=(int(sqrt(a[i][j])))*(int(sqrt(a[i][j])));
  41. }
  42. }
  43. if(dif[x]==k) t++;
  44. if(dif[x]>maxim)
  45. maxim=dif[x];
  46. }
  47. else
  48. for(j=m; j>=1; j--)
  49. {
  50. x++;
  51. if(a[i][j]!=0)
  52. {
  53. if(a[i][j]==1)
  54. {
  55. dif[x]=0;
  56. v[x]=0;
  57. }
  58. else if(sqrt(a[i][j])==int(sqrt(a[i][j])))
  59. {
  60. dif[x]=a[i][j]-(sqrt(a[i][j])-1)*(sqrt(a[i][j])-1);
  61. v[x]=(sqrt(a[i][j])-1)*(sqrt(a[i][j])-1);
  62. }
  63. else
  64. {
  65. dif[x]=a[i][j]-(int(sqrt(a[i][j])))*(int(sqrt(a[i][j])));
  66. v[x]=(int(sqrt(a[i][j])))*(int(sqrt(a[i][j])));
  67. }
  68. }
  69. if(dif[x]==k) t++;
  70. if(dif[x]>maxim)
  71. maxim=dif[x];
  72. }
  73. }
  74. nr=1;
  75. smax=s=v[1];
  76. zi=1;
  77. for(i=1; i<=n*m; i++)
  78. if(dif[i]==dif[i+1])
  79. {
  80. nr++;
  81. s+=v[i+1];
  82. }
  83. else
  84. {
  85. if(dif[i]!=0)
  86. if(nr>lungime)
  87. {
  88. lungime=nr;
  89. zi=dif[i];
  90. smax=s;
  91. }
  92. else if(nr==lungime)
  93. {
  94. if(s>smax)
  95. {
  96. lungime=nr;
  97. zi=dif[i];
  98. smax=s;
  99. }
  100. else if(s==smax && dif[i]>zi)
  101. {
  102. lungime=nr;
  103. zi=dif[i];
  104. smax=s;
  105. }
  106.  
  107. }
  108. nr=1;
  109. s=v[i+1];
  110. }
  111. if(c==1)
  112. g<<maxim<<" "<<t;
  113. else
  114. g<<lungime<<" "<<zi;
  115. return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement