fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. struct Tragac
  6. {
  7. int r,c,v;
  8.  
  9. bool operator < (Tragac other)
  10. {
  11. return v > other.v;
  12. }
  13. };
  14.  
  15. Tragac tragac[1005];
  16. int matr[1005][1005];
  17. int visited[1005][1005];
  18. int main()
  19. {
  20. ios::sync_with_stdio(false);
  21. cin.tie(0);
  22. memset(matr,31,sizeof(matr));
  23. memset(visited,-1,sizeof(visited));
  24.  
  25. int n,r,c;
  26. cin >> r >> c >> n;
  27. queue<pair<int,int>> q[1005];
  28. int cnt=n;
  29. for(int i = 0;i<n;i++)
  30. {
  31. cin >> tragac[i].r >> tragac[i].c >> tragac[i].v;
  32. tragac[i].r--;
  33. tragac[i].c--;
  34. }
  35.  
  36. sort(tragac,tragac+n);
  37.  
  38. for(int i = 0;i<n;i++)
  39. {
  40. q[i].push({tragac[i].r,tragac[i].c});
  41. }
  42.  
  43. for(int i = 0;i<n;i++)
  44. {
  45. int cnt = 0;
  46. matr[q[i].front().first][q[i].front().second] = 0;
  47. while(!q[i].empty())
  48. {
  49. cnt++;
  50. for(int j = 0;j<tragac[i].v;j++)
  51. {
  52. int s = q[i].size();
  53. for(int x = 0;x<s;x++)
  54. {
  55. pair<int,int> pom = q[i].front();
  56. q[i].pop();
  57.  
  58. int red[4] = {0,1,0,-1};
  59. int kol[4] = {1,0,-1,0};
  60. for(int k = 0;k<4;k++)
  61. {
  62. int row = pom.first+red[k];
  63. int col = pom.second+kol[k];
  64.  
  65. if(row >= 0 && row < r && col >= 0 && col < c && cnt <= matr[row][col] && visited[row][col] != i)
  66. {
  67. visited[row][col] = i;
  68. matr[row][col] = cnt;
  69. q[i].push({row,col});
  70. }
  71. }
  72. }
  73. }
  74.  
  75. }
  76. }
  77.  
  78. int Max = -1;
  79. int ansR,ansC;
  80. for(int i = 0;i<r;i++)
  81. {
  82. for(int j =0 ;j<c;j++)
  83. {
  84. // cout << matr[i][j] << " ";
  85. if(matr[i][j] > Max)
  86. {
  87. Max = matr[i][j];
  88. ansR = i+1;
  89. ansC = j+1;
  90. }
  91. }
  92. //cout << "\n";
  93. }
  94.  
  95. cout << ansR << " " << ansC;
  96.  
  97. return 0;
  98. }
Success #stdin #stdout 0.01s 11696KB
stdin
Standard input is empty
stdout
0 0