fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <algorithm>
  5. #include <set>
  6. using namespace std;
  7. typedef long long ll;
  8.  
  9. int main() {
  10. int t;
  11. cin >> t;
  12. while(t--){
  13. ll n, m;
  14. string s;
  15. cin >> n >> m >> s;
  16. vector<vector<int> > a(n, vector<int>(m));
  17. vector<int> sumc(n);
  18. vector<int> sumr(m);
  19. for(int i = 0; i < n; i++){
  20. for(int j = 0; j < m; j++){
  21. cin >> a[i][j];
  22. sumc[i] += a[i][j];
  23. sumr[j] += a[i][j];
  24. }
  25. }
  26. int i = 0, j = 0;
  27. for(int x = 0; x < s.size(); x++){
  28. if(s[x] == 'D'){
  29. a[i][j] = - sumc[i];
  30. sumc[i] += a[i][j];
  31. sumr[j] += a[i][j];
  32. i++;
  33. }
  34. if(s[x] == 'R'){
  35. a[i][j] = - sumr[j];
  36. sumc[i] += a[i][j];
  37. sumr[j] += a[i][j];
  38. j++;
  39. }
  40. }
  41. a[i][j] = -sumr[j];
  42. cout << endl;
  43. for(int i = 0; i < n; i++){
  44. for(int j = 0; j < m; j++){
  45. cout << a[i][j] << " ";
  46. }
  47. cout << endl;
  48. }
  49. }
  50. }
Success #stdin #stdout 0s 5288KB
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