#define NOMINMAX #define TEST_MODE true #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include "bits/stdc++.h" #include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rep2(i,a,b) for(int i=(a);i<(int)(b);++i) #define rrep(i,n) for(int i=(n)-1;i>=0;--i) #define rrep2(i,a,b) for(int i=(a)-1;i>=(int)b;--i) #define range(i,a,b,c) for(int i=a;c>0?ib;i+=c) #define chmax(a,b) (a=(a)<(b)?(b):(a)) #define chmin(a,b) (a=(a)>(b)?(b):(a)) //templatevoid out(T a) {T b=a;if(a==inf)b=-1;cout< eps) - (r < -eps); } int sgn(const Real& a, const Real& b) { return sgn(a - b); } const int MAX = (int)2e6 + 5; const int MAX2 = 2005; vector split(const string& str, char sep) { vector v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) v.push_back(buffer); return v; } string join(const vector& v, const string delim = 0) { string s; if (!v.empty()) { s += v[0]; for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) { if (delim != "")s += delim; s += v[i]; } }return s; } string operator*(const string& s, const int& n) { string res = ""; rep(i, n)res += s; return res; } #define sum_f(a){return accumulate(all(a),0ll);} templateT gcd(T a, T b) { T c; while (a != 0) { c = a; a = b % a; b = c; }; return b; } templateT bit_count(T N) { T c = 0; while (N) { if (N & 1)c++; N >>= 1; }return c; } templatevoid print_vec(vector a, ostream& o = cout) { rep(i, a.size() - 1)o << a[i] << " "; o << a.back() << endl; } ll pow_n(ll x, ll n) { ll r = 1; while (n > 0) { if (n & 1)r = r * x; x = x * x; n >>= 1; }return r; } int H, W; #define grid_ng(y,x) (y<0||y>=H||x<0||x>=W) int div_ceil(int a, int b) { int r = a / b; if (a % b != 0)r++; return r; } #define i1(a) cin>>a; #define i2(a,b) cin>>a>>b; #define i3(a,b,c) cin>>a;i2(b,c); #define i4(a,b,c,d) cin>>a;i3(b,c,d); #define i5(a,b,c,d,e) cin>>a;i4(b,c,d,e); int cx = 0, cy = 0; void changeXY(char c) { if (c == 'U') cy = cy + 1; else if (c == 'D') cy = cy - 1; else if (c == 'R') cx = cx + 1; else cx = cx - 1; } template void in_vec(vector& a, int n) { a.resize(n); rep(i, n) cin >> a[i]; } template void in_vec(vector>& a) { a.resize(H); rep(i, H) { a[i].resize(W); rep(j, W) cin >> a[i][j]; } } template void out(First first) { cout << first << endl; } template void out(First first, Rest... rest) { cout << first << " "; out(rest...); } template auto make_vec(const size_t(&d)[n], const T& init) noexcept { if constexpr (idx < n) return std::vector(d[idx], make_vec(d, init)); else return init; } template auto make_vec(const size_t(&d)[n]) noexcept { return make_vec(d, T{}); } bool is_bit_on(int b, int i) { return (b >> i) & 1; } // end template vector field; vector> ans; vector bomb_cnt; vector>>> bomb; int bomb_id = 0; int n, m; int buy_cnt = 100; void print_ans(pair p) { cout << p.first << " " << p.second << endl; } void player_move(int move_x, int move_y) { if (move_x > 0) { rep(j, move_x) { print_ans(make_pair(1, "R")); } } else { rep(j, -move_x) { print_ans(make_pair(1, "L")); } } if (move_y > 0) { rep(j, move_y) { print_ans(make_pair(1, "D")); } } else { rep(j, -move_y) { print_ans(make_pair(1, "U")); } } } void buy_near_bomb(int y, int x) { rep(dist, H + W) { rep2(dx, -dist, dist + 1) { rep(i, 2) { int dy = dist - abs(dx); if (i == 1) dy = -dy; int nx = x + dx; int ny = y + dy; if (grid_ng(ny, nx)) continue; if (field[ny][nx] == '@') { dumpl(dy); dumpl(dx); int move_x = nx - x; int move_y = ny - y; player_move(move_x, move_y); bomb_cnt[bomb_id] += buy_cnt; rep(i, buy_cnt) { print_ans(make_pair(2, to_string(bomb_id + 1))); } player_move(-move_x, -move_y); return; } } } } } void use_bomb(int y, int x, int use_bomb_id) { auto a = bomb[use_bomb_id].second; rep(i, a.size()) { int nx = x + bomb[use_bomb_id].second[i].first; int ny = y + bomb[use_bomb_id].second[i].second; if (grid_ng(ny, nx)) continue; field[ny][nx] = '.'; } } void print_field() { rep(i, H) { rep(j, W) { cerr << field[i][j]; } cerr << endl; } } signed main() { cin >> n >> m; H = n; W = n; field.resize(H); for (int i = 0; i < H; i++) { cin >> field[i]; } bomb.resize(m); bomb_cnt.resize(m); for (int i = 0; i < m; i++) { int C, L; cin >> C >> L; bomb[i].first = C; for (int j = 0; j < L; j++) { int a, b; cin >> a >> b; bomb[i].second.push_back(make_pair(a, b)); } } //int x = -1, y = -1; //for (int i = 0; i < H; i++) { // for (int j = 0; j < H; j++) { // if (field[i][j] == '@') { // x = i; // y = j; // break; // } // } // if (x != -1)break; //} //for (int i = 0; i < x; i++) { // print_ans(make_pair(1, "D")); //} //for (int i = 0; i < y; i++) { // print_ans(make_pair(1, "R")); //} //for (int i = 0; i < H * H; i++) { // print_ans(make_pair(2, to_string(1))); //} //for (int i = 0; i < x; i++) { // print_ans(make_pair(1, "U")); //} //for (int i = 0; i < y; i++) { // print_ans(make_pair(1, "L")); //} for (int y = 0; y < H; y++) { for (int x = 0; x < W; x++) { // if (field[y][x] == '@') { // buy_near_bomb(x, y); // break; //} int nx = x; if (y % 2 == 1) { nx = H - 1 - x; } if (bomb_cnt[bomb_id] < buy_cnt) { buy_near_bomb(y, nx); } if (field[y][nx] == '#') { use_bomb(y, nx, bomb_id); } if (y == H - 1 && x == H - 1)break; else if (x == H - 1)print_ans(make_pair(1, "D")); else if (y % 2 == 0)print_ans(make_pair(1, "R")); else print_ans(make_pair(1, "L")); } } cout << ans.size() << endl; for (pair i : ans) { cout << i.first << " " << i.second << endl; } // print_field(); }