#include #include #include #include #include using namespace std; #pragma GCC optimize("O3") const int inf = 1e8; int bitnum (int a) { for (int i=0; i < 30; i++) { if ((1< MARKED; cin >> w >> h; int x_, y_; string who; cin >>x_ >> y_ >> who; x_--; y_--; MARKED.push_back(encode(x_,y_)); cin >> m; for (int i=0; i < m; i ++) { cin >>x_ >> y_; x_--; y_--; MARKED.push_back(encode(x_,y_)); } m++; n = w * h; vector > dist; dist.resize(n, vector(n, inf)); for (int x=0; x < w; x ++) { for (int y=0; y < h; y ++) { int src = encode(x, y); vector > deltas; dist[src][src] = 0; if (who == "R" || who == "Q") { for (int i=0; i <=15;i ++) { deltas.push_back({0, i}); deltas.push_back({0, -i}); deltas.push_back({i, 0}); deltas.push_back({-i, 0}); } } if (who == "K") { deltas = { {1,1}, {-1,-1}, {1,-1}, {-1,1}, {1,0}, {-1,0}, {0,1}, {0,-1} }; } if (who == "B"||who =="Q") { for (int i=0; i <=15;i ++) { deltas.push_back({i, i}); deltas.push_back({-i, i}); deltas.push_back({i, -i}); deltas.push_back({-i, -i}); } } if (who == "N") { deltas = { {-2,1}, {1,-2}, {1,-2}, {-2,1}, {2,-1}, {-1,2}, {-1,2}, {2,-1} }; } /*if (who == "Q") { deltas = { {-2,-2}, {-2,0}, {0,-2}, {-1,1}, {0,1}, {1,0}, {1,-1}, {1,1}}; }*/ for (auto d : deltas) { int ax = x + d.first; int ay = y + d.second; // if(ax<0||ax>=w || ay<0||ay>=h) continue; int dd = encode(ax,ay); dist[src][dd] =dist[dd][src] = 1; } } } for(int k=0;k > D (n, vector(1<= inf) cout << -1 << endl; else cout << res << endl; } /* cteam053@acm ~ $ ./king < k2.in 0 1 2 1 1 2 2 2 2 0 2 0 1 1 1 1 2 2 2 1 1 2 0 2 1 1 2 2 2 2 2 1 2 0 1 2 1 1 2 3 2 2 1 2 0 1 1 1 1 4 2 2 2 1 2 0 2 1 1 5 1 2 2 2 1 2 0 1 2 6 2 1 2 2 2 1 2 0 1 1 2 1 2 2 2 1 2 0 mask 1 mask 2 mask 3 x is 0 at 1 get 0 from 1 0 2 x is 1 at 3 1 4 x is 2 at 2 2 3 x is 3 at 3 3 3 x is 4 at 3 4 3 x is 5 at 3 5 4 x is 6 at 0 get 6 from 2 6 1 x is 7 at 3 7 4 x is 8 at 3 8 2 mask 4 mask 5 x is 0 at 1 0 4 x is 1 at 3 1 3 x is 2 at 2 get 2 from 1 2 2 x is 3 at 3 3 3 x is 4 at 3 4 2 x is 5 at 3 5 4 x is 6 at 0 get 6 from 4 6 2 x is 7 at 3 7 4 x is 8 at 3 8 2 mask 6 x is 0 at 1 get 0 from 4 0 2 x is 1 at 3 1 3 x is 2 at 2 get 2 from 2 2 1 x is 3 at 3 3 4 x is 4 at 3 4 3 x is 5 at 3 5 4 x is 6 at 0 6 3 x is 7 at 3 7 4 x is 8 at 3 8 2 mask 7 x is 0 at 1 get 0 from 5 0 3 x is 1 at 3 1 4 x is 2 at 2 get 2 from 3 2 3 x is 3 at 3 3 4 x is 4 at 3 4 3 x is 5 at 3 5 5 x is 6 at 0 get 6 from 6 6 3 x is 7 at 3 7 5 x is 8 at 3 8 3 3 */