Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <algorithm>
- #include <string>
- #include <set>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- long long t;
- cin >> t;
- while (t--) {
- int n, m;
- cin >> n >> m;
- string s;
- cin >> s;
- int arr[n][m];
- for (int i=0; i<n; i++) {
- for (int j=0; j<m; j++) {
- cin >> arr[i][j];
- }
- }
- long long sum=0;
- int r=0, c=0;
- for (int i=0; i<s.size(); i++) {
- if (s[i]=='R') {
- for (int k=0; k<n; k++) {
- sum+=arr[k][c];
- }
- arr[r][c]=-1*sum;
- c++;
- }
- else {
- for (int k=0; k<m; k++) {
- sum+=arr[r][k];
- }
- arr[r][c]=-1*sum;
- r++;
- }
- sum=0;
- }
- for (int k=0; k<n; k++) {
- sum+=arr[k][m-1];
- }
- arr[n-1][m-1]=-1*sum;
- for (int i=0; i<n; i++) {
- for (int j=0; j<m; j++) {
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment