fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. const int MOD = 1e9 + 7;
  7.  
  8. void solve(){
  9. int n, m;
  10. cin >> n >> m;
  11. string s;
  12. cin >> s;
  13.  
  14. int a[n][m];
  15.  
  16. ll s1[n], s2[m];
  17. memset(s1, 0, sizeof s1);
  18. memset(s2, 0, sizeof s2);
  19. for(int i = 0; i < n; i++){
  20. for(int j = 0; j < m; j++){
  21. cin >> a[i][j];
  22. s1[i] += a[i][j];
  23. s2[j] += a[i][j];
  24. }
  25. }
  26. int x = 0, y = 0;
  27. for(int i = 0; i < s.size(); i++){
  28. if(s[i] == 'R'){
  29. a[x][y] = -s2[y];
  30. s1[x] += (-s2[y]);
  31. s2[y] = 0;
  32. y++;
  33. }else{
  34. a[x][y] = -s1[x];
  35. s2[y] += (-s1[x]);
  36. s1[x] = 0;
  37. x++;
  38. }
  39. }
  40. a[n - 1][m - 1] = -s1[n - 1];
  41.  
  42. for(int i = 0; i < n; i++){
  43. for(int j = 0; j < m; j++)cout << a[i][j] <<" ";
  44. cout << "\n";
  45. }
  46.  
  47. }
  48.  
  49. int main(){
  50. ios_base::sync_with_stdio(false);
  51. cin.tie(nullptr);
  52.  
  53. int t = 1;
  54. cin >> t;
  55.  
  56. for(int i = 1; i <= t; i++){
  57. solve();
  58. }
  59. return 0;
  60. }
Success #stdin #stdout 0.01s 5284KB
stdin
4
3 3
DRRD
0 2 3
0 0 0
3 1 0
4 5
DRRRRDD
0 1 0 2 3
0 0 0 0 0
-1 0 -3 -3 0
0 0 0 -1 0
2 3
RRD
0 0 0
0 1 0
5 5
DDDDRRRR
0 25 2 9 11
0 6 13 20 22
0 17 24 1 8
0 3 10 12 19
0 0 0 0 0
stdout
-5 2 3 
2 -3 1 
3 1 -4 
-6 1 0 2 3 
7 -1 3 2 -11 
-1 0 -3 -3 7 
0 0 0 -1 1 
0 -1 1 
0 1 -1 
-47 25 2 9 11 
-61 6 13 20 22 
-50 17 24 1 8 
-44 3 10 12 19 
202 -51 -49 -42 -60