-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrcprt.cpp
More file actions
125 lines (124 loc) · 2.46 KB
/
frcprt.cpp
File metadata and controls
125 lines (124 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pr pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--) {
int n,m;
cin>>n>>m;
vector<string> s(n);
vector<int> row(n,0),col(m,0);
for(int i=0;i<n;i++)
cin>>s[i];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++) {
if(s[i][j]=='1') {
row[i]++;
col[j]++;
}
}
}
string d;
cin>>d;
//int l=0,r=0,u=0,e=0;
for(int i=0;i<d.size();i++) {
if(d[i]=='L') {
// l++;
// if(r=!0) {
// r=0;
//cout<<d[i]<<" ";
for(int i=0;i<n;i++) {
int k=0;
for(int j=0;j<m;j++) {
if(k<row[i]) {
if(s[i][j]=='0')
col[j]++;
s[i][j]='1';
k++;
} else {
if(s[i][j]=='1')
col[j]--;
s[i][j]='0';
}
}
}
//}
} else if(d[i]=='R') {
// r++;
// if(l!=0) {
// l=0;
//cout<<d[i]<<" ";
for(int i=n-1;i>=0;i--) {
int k=0;
for(int j=m-1;j>=0;j--) {
if(k<row[i]) {
if(s[i][j]=='0')
col[j]++;
s[i][j]='1';
k++;
} else {
if(s[i][j]=='1')
col[j]--;
s[i][j]='0';
}
}
}
// }
} else if(d[i]=='D') {
// d++;
// if(u=!0) {
// u=0;
//cout<<d[i]<<" ";
for(int i=m-1;i>=0;i--) {
int k=0;
for(int j=n-1;j>=0;j--) {
if(k<col[i]) {
if(s[j][i]=='0')
row[j]++;
s[j][i]='1';
k++;
} else {
if(s[j][i]=='1')
row[j]--;
s[j][i]='0';
}
}
}
// }
} else if(d[i]=='U') {
// u++;
// if(=!0) {
// d=0;
//cout<<d[i]<<" ";
for(int i=0;i<m;i++) {
int k=0;
for(int j=0;j<n;j++) {
if(k<col[i]) {
if(s[j][i]=='0')
row[j]++;
s[j][i]='1';
k++;
} else {
if(s[j][i]=='1')
row[j]--;
s[j][i]='0';
}
}
}
//}
}
}
for(int i=0;i<n;i++)
cout<<s[i]<<"\n";
}
return 0;
}