Advertisement
a53

Ronti

a53
Mar 29th, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. /* autor Razvan Chivu */
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. int a[101][101];
  9.  
  10. int n, m, k;
  11.  
  12. bool inmat(int x, int y){
  13. if(x >= 1 && x <= n && y >= 1 && y <= m)
  14. return true;
  15. return false;
  16. }
  17.  
  18. void rec(int x, int y, int &s){
  19. s += a[x][y];
  20. a[x][y] = 0;
  21.  
  22. int px = x, py = y;
  23.  
  24. for(int i = 1; i <= k; i++){
  25. px = x - i;
  26. py = y;
  27. if(inmat(px, py) && a[px][py])
  28. rec(px, py, s);
  29.  
  30. px = x + i;
  31. py = y;
  32. if(inmat(px, py) && a[px][py])
  33. rec(px, py, s);
  34.  
  35. px = x;
  36. py = y - i;
  37. if(inmat(px, py) && a[px][py])
  38. rec(px, py, s);
  39.  
  40. px = x;
  41. py = y + i;
  42. if(inmat(px, py) && a[px][py])
  43. rec(px, py, s);
  44.  
  45. }
  46. }
  47.  
  48. int main()
  49. {
  50. ifstream fin("ronti.in");
  51. ofstream fout("ronti.out");
  52.  
  53. fin >> n >> m >> k;
  54.  
  55. for(int i = 1; i <= n; i++)
  56. for(int j = 1; j <= m; j++)
  57. fin >> a[i][j];
  58.  
  59. int smax = 0;
  60. int xmax=0, ymax=0;
  61. for(int i = 1; i <= n; i++)
  62. for(int j = 1; j <= m; j++)
  63. if(a[i][j]){
  64. int s = 0;
  65. rec(i, j, s);
  66. if(s > smax){
  67. smax = s;
  68. xmax = i;
  69. ymax = j;
  70. }
  71. }
  72.  
  73. fout << xmax << " " << ymax << "\n" << smax;
  74.  
  75.  
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement