lina_os

Untitled

Jan 23rd, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <string>
  6. #include <set>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  12. long long t;
  13. cin >> t;
  14. while (t--) {
  15. int n, m;
  16. cin >> n >> m;
  17. string s;
  18. cin >> s;
  19. int arr[n][m];
  20. for (int i=0; i<n; i++) {
  21. for (int j=0; j<m; j++) {
  22. cin >> arr[i][j];
  23. }
  24. }
  25.  
  26.  
  27. long long sum=0;
  28. int r=0, c=0;
  29.  
  30. for (int i=0; i<s.size(); i++) {
  31. if (s[i]=='R') {
  32. for (int k=0; k<n; k++) {
  33. sum+=arr[k][c];
  34. }
  35. arr[r][c]=-1*sum;
  36. c++;
  37. }
  38. else {
  39. for (int k=0; k<m; k++) {
  40. sum+=arr[r][k];
  41. }
  42. arr[r][c]=-1*sum;
  43. r++;
  44. }
  45. sum=0;
  46. }
  47. for (int k=0; k<n; k++) {
  48. sum+=arr[k][m-1];
  49. }
  50. arr[n-1][m-1]=-1*sum;
  51.  
  52.  
  53. for (int i=0; i<n; i++) {
  54. for (int j=0; j<m; j++) {
  55. cout << arr[i][j] << " ";
  56. }
  57. cout << endl;
  58. }
  59.  
  60. }
  61.  
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment