QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#153437 | #5472. Secure the Top Secret | ideograph_advantage | AC ✓ | 12ms | 18296kb | C++17 | 8.9kb | 2023-08-30 02:19:52 | 2023-08-30 02:19:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define iter(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef LOCAL
void debug(){cerr << "\n";}
template<class T, class ... U>
void debug(T a, U ... b){ cerr << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
while(l != r) cerr << *l << " ", l++;
cerr << "\n";
}
#else
#define debug(...) void()
#define pary(...) void()
#endif
template<class A, class B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.ff << ',' << p.ss << ')';
}
const ll MAX = 1e9;
#define maxn 250000
#define inf 1000000000
struct MCMF{
struct edge {
ll from, to, cap, flow, cost, rev;
} * past[maxn];
vector<edge> G[maxn];
bitset<maxn>inq;
ll dis[maxn], up[maxn], s, t, mx, n;
bool BellmanFord(ll &flow, ll &cost) {
fill(dis, dis+n, inf);
queue<ll> q;
q.push(s);
inq.reset(), inq[s] = 1;
up[s] = mx - flow, past[s] = 0, dis[s] = 0;
while (!q.empty()) {
ll u = q.front();
q.pop(), inq[u] = 0;
if (!up[u]) continue;
for (auto &e :G[u]) {
if (e.flow != e.cap && dis[e.to] > dis[u] + e.cost) {
dis[e.to] = dis[u] + e.cost, past[e.to] = &e;
up[e.to] = min(up[u], e.cap - e.flow);
if (!inq[e.to]) inq[e.to] = 1, q.push(e.to);
}
}
}
if (dis[t] == inf) return 0;
flow += up[t], cost += up[t] * dis[t];
for (ll i = t;past[i];i = past[i]->from) {
auto &e = *past[i];
e.flow += up[t], G[e.to][e.rev].flow -= up[t];
}
return 1;
}
ll MinCostMaxFlow(ll _s, ll _t, ll &cost) {
s = _s, t = _t, cost = 0;
ll flow = 0;
while (BellmanFord(flow, cost));
//debug("ok", flow, cost);
for(int i = 0; i < n; i++){
for(auto j : G[i]){
if(j.flow > 0) debug("edge", j.from, j.to, j.flow);
}
}
return flow;
}
void init(ll _n, ll _mx) {
n = _n, mx = _mx;
for (int i = 0;i < n;i++) G[i].clear();
}
void add_edge(ll a, ll b, ll cap, ll cost) {
debug("add_edge", a, b, cap, cost);
G[a].pb(edge{a, b, cap, 0, cost, SZ(G[b])});
G[b].pb(edge{b, a, 0, 0, -cost, SZ(G[a]) - 1});
}
} flow;
#define X ff
#define Y ss
struct border{
pii A, B, cell;
int side;
};
bool operator==(border a, border b){
return a.A == b.A && a.B == b.B && a.cell == b.cell && a.side == b.side;
}
ostream& operator<<(ostream& o, border b){
return o << '(' << b.A << ',' << b.B << ',' << b.cell << ',' << b.side << ')';
}
pair<pii, pii> get_edge(int x, int y, int side){
if(side == 0) return {mp(x, y), mp(x - 1, y)};
if(side == 1) return {mp(x - 1, y), mp(x - 1, y - 1)};
if(side == 2) return {mp(x - 1, y - 1), mp(x, y - 1)};
if(side == 3) return {mp(x, y - 1), mp(x, y)};
assert(false);
}
pii get_adj(int x, int y, int side){
if(side == 0) return {x, y + 1};
if(side == 1) return {x - 1, y};
if(side == 2) return {x, y - 1};
if(side == 3) return {x + 1, y};
assert(false);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cerr.tie(0);
int n, m;
cin >> n >> m;
flow.init((n + 1) * (m + 1) + 4, 1e9);
auto addedge = [&](int x1, int y1, int x2, int y2, int w){
if(x1 == x2 && (x1 == 0 || x1 == n)) return;
if(y1 == y2 && (y1 == 0 || y1 == m)) return;
flow.add_edge(x1 * (m + 1) + y1, x2 * (m + 1) + y2, 2 - w, w);
flow.add_edge(x2 * (m + 1) + y2, x1 * (m + 1) + y1, 2 - w, w);
};
pii S, U, T;
vector<string> s(n + 2);
s[0] = s[n + 1] = string(m + 2, '#');
for(int i = 1; i <= n; i++){
cin >> s[i];
s[i] = "#" + s[i] + "#";
for(int j = 1; j <= m; j++){
if(s[i][j] == 'S') S = mp(i, j);
if(s[i][j] == 'T') T = mp(i, j);
if(s[i][j] == 'U') U = mp(i, j);
}
}
int K;
cin >> K;
vector<pair<pii, pii>> wall;
for(int i = 0; i < K; i++){
int x, y;
char d;
cin >> x >> y >> d;
if(d == 'b') wall.pb(mp(x, y - 1), mp(x, y));
else wall.pb(mp(x - 1, y), mp(x, y));
}
vector<vector<int>> vst(n + 2, vector<int>(m + 2));
vector<pii> dir4 = {mp(0, 1), mp(1, 0), mp(-1, 0), mp(0, -1)};
vector<pii> dir8;
for(int i = -1; i <= 1; i++) for(int j = -1; j <= 1; j++) if(i != 0 || j != 0) dir8.pb(mp(i, j));
auto bfs = [&](int sx, int sy, int t, vector<pii> &dir){
queue<pii> q;
q.push(mp(sx, sy));
vst[sx][sy] = t;
while(!q.empty()){
auto [x, y] = q.front();
q.pop();
for(auto [dx, dy] : dir){
int nx = x + dx, ny = y + dy;
if(nx < 0 || nx > n + 1 || ny < 0 || ny > m + 1) continue;
if(vst[nx][ny]) continue;
if(t == 1 && s[nx][ny] == '#') continue;
vst[nx][ny] = t;
q.push(mp(nx, ny));
}
}
};
bfs(S.X, S.Y, 1, dir4);
for(int i = 0; i <= n + 1; i++) pary(iter(vst[i]));
bfs(0, 0, -1, dir8);
for(int i = 0; i <= n + 1; i++) pary(iter(vst[i]));
if(vst[U.X][U.Y] != 1){
cout << "0\n";
return 0;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(vst[i][j]) continue;
addedge(i, j, i, j - 1, 0);
addedge(i, j, i - 1, j, 0);
addedge(i - 1, j - 1, i, j - 1, 0);
addedge(i - 1, j - 1, i - 1, j, 0);
}
}
border bor;
{
int side;
if(T.X == 1) side = 1;
else if(T.X == n) side = 3;
else if(T.Y == 1) side = 2;
else side = 0;
auto [A, B] = get_edge(T.X, T.Y, side);
bor = border({A, B, T, side});
}
border fst = bor;
int lst = 0;
char c1 = 'T';
int s1 = (n + 1) * (m + 1);
int s2 = s1 + 1;
int t1 = s2 + 1;
int t2 = t1 + 1;
bool ST = false;
vector<vector<bool>> bad(n + 2, vector<bool>(m + 2));
vector<pii> pts = {bor.A};
int cnt = 0;
auto zuoshi = [&](int nxt, char c2, int to){
//debug("check zuoshi", lst, c2, SZ(bor));
if(c2 == '.') return;
debug("zuoshi", lst, nxt, c1, c2);
if(mp(c1, c2) == mp('S', 'U') ||
mp(c1, c2) == mp('U', 'S') ||
mp(c1, c2) == mp('U', 'T') ||
mp(c1, c2) == mp('T', 'U')){
debug("OK SU/UT");
for(int i = lst; i <= to; i++){
auto A = pts[i];
if(cnt == 0)
flow.add_edge(s1, A.X * (m + 1) + A.Y, 2, 0);
else
flow.add_edge(A.X * (m + 1) + A.Y, t1, 2, 0);
}
cnt++;
}
else if(mp(c1, c2) == mp('S', 'T') ||
mp(c1, c2) == mp('T', 'S')){
debug("OK ST");
for(int i = lst; i <= to; i++){
auto A = pts[i];
bad[A.X][A.Y] = true;
}
ST = true;
}
lst = nxt;
c1 = c2;
//debug("ok zuoshi");
};
bool go = false;
while(true){
auto [A, B, cell, side] = bor;
debug("border", A, B, cell, side);
pts.pb(bor.B);
zuoshi(SZ(pts) - 1, s[cell.X][cell.Y], SZ(pts) - 2);
if(go && bor == fst) break;
go = true;
auto [tx, ty] = get_adj(cell.X, cell.Y, (side + 1) % 4);
if(vst[tx][ty] == -1){
auto [nA, nB] = get_edge(cell.X, cell.Y, (side + 1) % 4);
bor = border({nA, nB, cell, (side + 1) % 4});
continue;
}
auto [nx, ny] = get_adj(tx, ty, side);
if(vst[nx][ny] == -1){
auto [nA, nB] = get_edge(tx, ty, side);
bor = border({nA, nB, mp(tx, ty), side});
continue;
}
zuoshi(SZ(pts) - 1, s[tx][ty], SZ(pts) - 1);
auto [nA, nB] = get_edge(nx, ny, (side - 1 + 4) % 4);
bor = border({nA, nB, mp(nx, ny), (side - 1 + 4) % 4});
}
pary(iter(pts));
if(!ST){
cout << "-1\n";
return 0;
}
//debug("ok");
for(auto [p1, p2] : wall){
if(bad[p1.X][p1.Y] || bad[p2.X][p2.Y]) continue;
addedge(p1.X, p1.Y, p2.X, p2.Y, 1);
}
flow.add_edge(s2, s1, 2, 0);
flow.add_edge(t1, t2, 2, 0);
debug("st", s1, s2, t1, t2);
ll ans = MAX;
if(flow.MinCostMaxFlow(s2, t2, ans) < 2) cout << "-1\n";
else cout << ans << "\n";
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 13680kb
input:
3 3 S.. #.. U.T 7 1 2 b 1 3 b 2 2 b 2 2 r 2 3 b 3 1 r 3 2 r
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 13704kb
input:
2 2 ST .U 4 1 1 r 1 1 b 1 2 b 2 1 r
output:
-1
result:
ok single line: '-1'
Test #3:
score: 0
Accepted
time: 3ms
memory: 13716kb
input:
7 10 U......... .......... ###....... .......... .......### .......... S........T 18 4 4 r 5 4 r 6 7 r 7 7 r 3 4 b 3 5 b 3 6 b 3 7 b 3 8 b 3 9 b 3 10 b 5 1 b 5 2 b 5 3 b 5 4 b 5 5 b 5 6 b 5 7 b
output:
14
result:
ok single line: '14'
Test #4:
score: 0
Accepted
time: 2ms
memory: 11760kb
input:
2 5 .T.#S ....U 10 1 3 b 1 1 r 1 1 b 2 1 r 1 2 b 1 5 b 2 2 r 1 2 r 2 3 r 2 4 r
output:
-1
result:
ok single line: '-1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 11704kb
input:
5 5 U.S.. ..... ..... ..... .T... 12 2 4 b 4 1 b 2 2 r 1 5 b 2 2 b 4 3 b 5 3 r 1 2 b 3 2 r 2 1 r 3 3 r 2 4 r
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 1ms
memory: 13676kb
input:
5 4 .... ...U .... S#.. .#T. 12 3 4 b 2 1 b 4 3 r 2 2 b 4 3 b 3 3 r 2 3 r 1 1 b 2 2 r 4 4 b 3 1 b 1 3 r
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 3ms
memory: 13672kb
input:
3 3 UST ### .#. 2 1 1 r 1 2 r
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 3ms
memory: 13756kb
input:
4 2 U. .. .T S. 8 1 1 b 3 1 r 4 1 r 1 1 r 2 2 b 3 2 b 3 1 b 2 1 r
output:
5
result:
ok single line: '5'
Test #9:
score: 0
Accepted
time: 1ms
memory: 13692kb
input:
2 2 S. UT 4 1 1 b 1 2 b 2 1 r 1 1 r
output:
-1
result:
ok single line: '-1'
Test #10:
score: 0
Accepted
time: 3ms
memory: 13704kb
input:
3 4 #U.T #... .S#. 3 1 2 r 2 2 b 3 1 r
output:
-1
result:
ok single line: '-1'
Test #11:
score: 0
Accepted
time: 1ms
memory: 13788kb
input:
3 5 .U.S. .#.## #.T#. 7 1 3 r 1 2 r 1 4 r 1 1 b 1 3 b 2 3 b 3 2 r
output:
-1
result:
ok single line: '-1'
Test #12:
score: 0
Accepted
time: 1ms
memory: 13700kb
input:
4 4 .T.S #.#. .... U... 6 3 1 b 1 4 b 2 4 b 3 2 b 4 1 r 3 2 r
output:
-1
result:
ok single line: '-1'
Test #13:
score: 0
Accepted
time: 1ms
memory: 9656kb
input:
5 5 .##T. ##.#. .#... ##.## #SU.. 6 2 3 b 3 3 r 4 3 b 1 5 b 3 4 r 5 4 r
output:
-1
result:
ok single line: '-1'
Test #14:
score: 0
Accepted
time: 0ms
memory: 14024kb
input:
97 97 S...............................................................................................T ................................................................................................. ................................................................................................. ...
output:
130
result:
ok single line: '130'
Test #15:
score: 0
Accepted
time: 4ms
memory: 14040kb
input:
100 94 S............................................................................................T .............................................................................................. .............................................................................................. ...........
output:
126
result:
ok single line: '126'
Test #16:
score: 0
Accepted
time: 4ms
memory: 14060kb
input:
95 92 S..........................................................................................T ............................................................................................ ............................................................................................ ..................
output:
124
result:
ok single line: '124'
Test #17:
score: 0
Accepted
time: 2ms
memory: 14232kb
input:
92 92 S..........................................................................................T ............................................................................................ ............................................................................................ ..................
output:
124
result:
ok single line: '124'
Test #18:
score: 0
Accepted
time: 4ms
memory: 14148kb
input:
96 100 S..................................................................................................T .................................................................................................... ..............................................................................................
output:
134
result:
ok single line: '134'
Test #19:
score: 0
Accepted
time: 4ms
memory: 14280kb
input:
92 90 S........................................................................................T .......................................................................................... .......................................................................................... ........................
output:
120
result:
ok single line: '120'
Test #20:
score: 0
Accepted
time: 2ms
memory: 14240kb
input:
96 90 S........................................................................................T .......................................................................................... .......................................................................................... ........................
output:
120
result:
ok single line: '120'
Test #21:
score: 0
Accepted
time: 1ms
memory: 12332kb
input:
92 94 S............................................................................................T .............................................................................................. .............................................................................................. ............
output:
126
result:
ok single line: '126'
Test #22:
score: 0
Accepted
time: 4ms
memory: 12412kb
input:
99 94 S............................................................................................T .............................................................................................. .............................................................................................. ............
output:
126
result:
ok single line: '126'
Test #23:
score: 0
Accepted
time: 5ms
memory: 14412kb
input:
93 91 S.........................................................................................T ........................................................................................... ........................................................................................... .....................
output:
122
result:
ok single line: '122'
Test #24:
score: 0
Accepted
time: 2ms
memory: 15548kb
input:
50 83 ........................#.............................#........#......#.....#...... ...........................................#........#................#........#.... ....................#.....#........................................................ ................................#............
output:
22
result:
ok single line: '22'
Test #25:
score: 0
Accepted
time: 0ms
memory: 14640kb
input:
58 98 .........#.....#...U............#..............#.......#....................##...........#........ .........#........#.....#...#..#........#.#.........#..................#.#........................ .#.##.......#........#......#..#.....#.........#..#.........#...##.........###..##......#..........
output:
-1
result:
ok single line: '-1'
Test #26:
score: 0
Accepted
time: 7ms
memory: 15540kb
input:
80 48 ..##.#.........#...#.....#............#.#.#.#... ....#........#.......#...#.##.#.##....#.##.#...# #......##.#..#.......#.....##..#..#.......##.#.# .##.#...#.#.#.#.....###...#......#............## .....#.#.....#.#..##.......##..#...#.#..#..##... .......#....#.#...##.##.##....#...#......#..#### ...
output:
2
result:
ok single line: '2'
Test #27:
score: 0
Accepted
time: 0ms
memory: 14676kb
input:
40 49 #.....................#..................#....... ..................#......#....#..#....#.#.......U ......#.................................#........ ................................................. #.......#.......#..........#..................... ....#.......#.......#............#.............
output:
9
result:
ok single line: '9'
Test #28:
score: 0
Accepted
time: 1ms
memory: 13808kb
input:
25 39 .......................#............... ...................................#... ....................................... ##.......................#............. ..................#.........#.......... ..#...................................U ...............................#....... .................
output:
-1
result:
ok single line: '-1'
Test #29:
score: 0
Accepted
time: 3ms
memory: 11784kb
input:
17 47 ..#.....#...#...#........................T.#... .........................#.........#......#.... .....#..........##..#.......#...#........#..... ......#.......................#................ ##...#........#.......##.#.#.......#.##........ ............................................... #..#.....
output:
-1
result:
ok single line: '-1'
Test #30:
score: 0
Accepted
time: 1ms
memory: 14036kb
input:
18 66 ...#..#...#..#.#...#U#.#....##...#.#.#.......#.#..........#......# ....##...#...##..##.....#..#.##.#..##...........#....#.....#...#.# #...##..........##.....#........#...##.#.##............#.#...#.#.. #.#..#..#........#..#....#...#..#.....##..#..#..............#....# .........#...##.#..#.#.###...
output:
4
result:
ok single line: '4'
Test #31:
score: 0
Accepted
time: 2ms
memory: 14204kb
input:
69 81 .....#..........#.##..U....#..#.S#....#..###..##...........#....##..####.#T.##.## ##........##...##.#.#.##...#.###.#...#....##..#...#..###.....#.................#. .......##...###..#....#..###.....#..##...#....#..#..#...#.#...#.#....#...##...#.# #...#...........##..###.#.#.##.#...#.#....#..#.#...
output:
2
result:
ok single line: '2'
Test #32:
score: 0
Accepted
time: 5ms
memory: 14740kb
input:
87 26 .##....#.U.#.#.#......#... ...#...##..#...#.##...#..T #..........#...#.....#.#.. ##.#..##...##.#..#..#..... ................##.....##. ......###..##.#..#..#..... ...#.....#....##..#....... #.......###..#.....#...... ######..##......#.....#... #.#.#....#.#.........#..#. .#.....#..###..#......#....
output:
4
result:
ok single line: '4'
Test #33:
score: 0
Accepted
time: 1ms
memory: 12236kb
input:
19 92 .#....#.#.....#.#.........###..S##.#...#..#.#..#...#..####.......#.......#...#.##.##...##... .......#.#.#.#..#...#..###..#...#..#....#......##........#.#.........#..#.###....#.....#.... ......#...#..#.#...#.....##..##......##.###....#...#....#.#.###..#...#####.##..#....#..#.### .##...##.#.#..#...
output:
2
result:
ok single line: '2'
Test #34:
score: 0
Accepted
time: 6ms
memory: 15816kb
input:
92 96 ...#..##.#..##.......#.....#..#.#S#....#.........##...#.#..#...#.......#..#............#..#..#.. ...#.#.#.#....#.##....#....#.#....#...#...#....#..##....#..#....#...#..#....#....##....#..#..... .#...#..#.........#..........#.##.#..#..#.#..#..#.....#.#....#.#.#..........##.......#.#....##.. ......
output:
-1
result:
ok single line: '-1'
Test #35:
score: 0
Accepted
time: 8ms
memory: 17572kb
input:
90 90 ##....#........#..#..#.#...#...#.#....#.#....##..#.#......#...#......T.#..####........#.#. ..#...............#.#...#...#......#.......#.#..#.#.......#...#.....##....#..##.....#..... .###.......##.##.........#.#.#..##.##..#........#.#......#......#.#.#..###..##..#.#.....#. ..##......#.........#...
output:
6
result:
ok single line: '6'
Test #36:
score: 0
Accepted
time: 7ms
memory: 16192kb
input:
98 93 ..#...........##..........##.#......#....#.....#.......#..#.#.#.......#..................U.#. ..#........#..#..#...#...##.................#.#........#.......##.#..#..#.....#.......#.###.# ...........###..#####.#..##.......#.#........#.#.....#.......#......#....#..#..#............. #...#.#........
output:
-1
result:
ok single line: '-1'
Test #37:
score: 0
Accepted
time: 7ms
memory: 16156kb
input:
96 97 #............#.................#....#.#.#...#....#..###..#.#....#.##...#..#...........#.......... ..#.........##........#...#.##....##....###...#.###..#.#..............##.#.....................#. ..#..........#.#.#..#...........#...##............#......##...................#......##....#..... ...
output:
-1
result:
ok single line: '-1'
Test #38:
score: 0
Accepted
time: 7ms
memory: 15464kb
input:
91 94 #...........#.#.##.#..#.....#.#........S.##.......##....#..#........#..#...#..#..#........#U#. ...#.....#..#.....##.#..#.##....#...#.##....#....#......##.#.#............##.......#....#....# #..#...#..#...#.#..###.#...#....#..##....#....##....#.#.##.........#..#...#.#........#.#.#..## ....##......
output:
4
result:
ok single line: '4'
Test #39:
score: 0
Accepted
time: 1ms
memory: 16284kb
input:
94 91 ...........#......#...#.....#..###.....#.......#....##.#....#........#......####.......#... ..#...###...##.......#..#....#..#.###.#....#......#.#..####.##...#...#..##..#.#...###..#... ..#.#.##..#...........#.........#.#.......#...........#.###......#..#....#......#...#...... .#.....##..#.....#...
output:
21
result:
ok single line: '21'
Test #40:
score: 0
Accepted
time: 5ms
memory: 15116kb
input:
90 94 ##..........#.#.#.....#.....#..#..#......#.#..##..##....##..#.#.#..#.###.#...#.........T.#.... ....#.#.....#.#...............##..#..##.##.#..#....##....###.#.#.#...#..###.........#.##....## ...##.............#..#.....#..#..#.......#....#...###....#.#..#...#.#....#...###..####........ #..##...#...
output:
24
result:
ok single line: '24'
Test #41:
score: 0
Accepted
time: 3ms
memory: 13220kb
input:
93 98 .............#.........#.....U..#......................##......................................... ...........#............#...........................................................###...#....... ....................................................................................#..............
output:
-1
result:
ok single line: '-1'
Test #42:
score: 0
Accepted
time: 3ms
memory: 16952kb
input:
96 100 ..........#........#..#...#..#.........#....#....#.#.....##......##....##............#.............# .......#.#..#.#.#..#....................#..............##.....#.........#...#...#.....#.....#.....#. ##.....##.#.###...#...#.#.............###.#.......#.#................#........#........##.....
output:
12
result:
ok single line: '12'
Test #43:
score: 0
Accepted
time: 10ms
memory: 16992kb
input:
100 99 ................#..#............T.....#.....#.....#............#.#.....U.#..#.....#..........#..... .................................#.#............................................................... ............#..........#..#..#.........#...................#............................#.......
output:
100
result:
ok single line: '100'
Test #44:
score: 0
Accepted
time: 1ms
memory: 11636kb
input:
13 22 ..#...#U#......#....## ......##.............# ......#....#...#.....# .........#..#......... ...................#.. ......###.........#..# ....#..............#.T .#..#...#............. #.....#.....##...#.... .#.........#.##....... ......#..#............ .#.....#...#...#...... ..S..#.#.............
output:
0
result:
ok single line: '0'
Test #45:
score: 0
Accepted
time: 3ms
memory: 11740kb
input:
84 35 ...#.#.#.......###..#......##.###.. ...#....##.#..##......###.#..#.##.. ...###.....#..###.#..#.#..#...#...# #...###.#..#..#....#...#.#.#.....#. ###...##......#.##.#.....#...#.#..# ...#.#...###......#.....#....#....# #.#..##.##.###...#..###....##.##... ###..#.#........#...#.#.##.#.#..... ...#.....
output:
0
result:
ok single line: '0'
Test #46:
score: 0
Accepted
time: 3ms
memory: 11716kb
input:
3 82 #..#.#.....#........#.##........####...#...#..##...#......#..S.##..#..#..#..##..#. ...#..##.............#...#..#....#...............#.#....##....#................... .#..............U................#...#...##.......#..#...T.#..#......#...#......#. 250 2 73 b 2 19 r 3 11 r 2 13 r 2 35 b 3 64 r ...
output:
0
result:
ok single line: '0'
Test #47:
score: 0
Accepted
time: 4ms
memory: 11760kb
input:
85 67 ...##....##..#..#....##..##S.##...#....#.#............#............ .......#.#..#....#..#..#.#...##..##.#...#.#.#...#......#.....##..#. ..#.....#.....#.#.......#.....#.......#..#.###..#.........#........ ##.#.#.#.#.###.#..........##....#.....#.#..##.#...........#...###.# ...........#.......#.....
output:
0
result:
ok single line: '0'
Test #48:
score: 0
Accepted
time: 3ms
memory: 11672kb
input:
42 30 ##.....##.#.#T.#.#.#.#....#.#. ..#.......##...#.#.#...#...... #.........#...#.##....#..#.... .....#..#....#..#...##...####. #.......###...#..#......#..#.. ...#.....#......#..#......#.## ##.#.#.#..#...#.......####.... ....#...##.....#....#.#.#..... ........#..#.#......#....#.#.. .#.##.#...###.....
output:
0
result:
ok single line: '0'
Test #49:
score: 0
Accepted
time: 2ms
memory: 15512kb
input:
62 62 ..........##...#.#.............#.#..........#................. ...............#.#............#..........................#.... ...................#.........................##............... ........#............#..................#................#.... ..........................#..#.......##......
output:
8
result:
ok single line: '8'
Test #50:
score: 0
Accepted
time: 8ms
memory: 16576kb
input:
89 74 ...#....#.#....#...........#..#T.#....................##.U.............##. ...##.....#......##......................#....#.#..#....#..#........##.... ...#.##............#...#.........#........#.#..........##.#..#............ .#.......#.....#.....#..#..............##.#................#............
output:
4
result:
ok single line: '4'
Test #51:
score: 0
Accepted
time: 4ms
memory: 15420kb
input:
100 37 .....................#..#.........#.. .............#........#........#..... ...........#......................... ..##..#.....#.............#.......... ............#..................#..... #..#................##...#........... ..#...........#...#.................. ..................#.#.....#...
output:
6
result:
ok single line: '6'
Test #52:
score: 0
Accepted
time: 4ms
memory: 15740kb
input:
44 89 ...#.#.#...##.#.#.....#..##..#.#......##.........#..##....#.....##....##.#.........#..#.. ##....##.#...........#...#..##.#....#...#.#.#......#........#..#..........#.......##....# ....#..#...#.#......#.#...###.#......#....#.#.#......#...##..............##.#.##...#..#.. .#.....###.#..#...#..#.....
output:
4
result:
ok single line: '4'
Test #53:
score: 0
Accepted
time: 3ms
memory: 14316kb
input:
68 17 ##.....#....#.... .#.##...#...#...# ...#....#....##.. ..#...#........#. ..#..####.#...##. .....###......... .#.........#..#.# ....#.#.#.#.....# ...#.....#....... #..#.###...####.. ..##.##....#.#... ##.....#.#.....#. ....#....#......# ..##............. .....#.........#. ....#...........# ..##.....
output:
6
result:
ok single line: '6'
Test #54:
score: 0
Accepted
time: 3ms
memory: 13848kb
input:
16 23 ..#..##.#U.#...#....#.# ...#...##.##.#...##...# ...#.#..#..##.#..#.#... ...#..#.#.#..#....#...# ##..#..#........#...... .......#.#.#........#.. .#.....#...#..#.#...... ........#..###.....###. .##.......#.###..##.#.. .....#..######......#.. #..#....#....#.#....#.# ....#.#..#....##....##. .#.#.....
output:
-1
result:
ok single line: '-1'
Test #55:
score: 0
Accepted
time: 1ms
memory: 11788kb
input:
43 67 .............#....#.............................S.#............#... ..........#.................#.............#........................ ................................#................................#. .........................#..........#...........#.................. ....#....................
output:
-1
result:
ok single line: '-1'
Test #56:
score: 0
Accepted
time: 1ms
memory: 13992kb
input:
79 22 .#......#..#...#.#...# ............#......... .###.......#.#..#....# ..#..#...........##... ......#.....###....#.# #.......#..#........#. .....#.....#.......... ......#.#.#.......#... ....#......##..#....#. ...#...#......##...... .....#...#.#..###..... .....###.......#...... #...........#..#.....
output:
-1
result:
ok single line: '-1'
Test #57:
score: 0
Accepted
time: 3ms
memory: 9744kb
input:
9 18 ...#...#....#....# .........##....... ..#.....#.#..###.U ...#..#..####...#T .#.###.##.......#. ......#....####.#. #....#....##.#..## S............#.#.. ###..#....#...#..# 0
output:
-1
result:
ok single line: '-1'
Test #58:
score: 0
Accepted
time: 1ms
memory: 14212kb
input:
40 72 #...#...#......#.#.#....#.##..##.#..##.#####..#.##...###.#.####..##..... .###.#..#.......#..#..#..#.#.#....##.....#..###.#..#.##..#.#.#....#....# ..#.#..#..#..#....#..####....#.#....##............#..#...##..#.#.#..#..# ####..#.##.....#..#........#.#......#...#..###.......##..#.............. .....
output:
-1
result:
ok single line: '-1'
Test #59:
score: 0
Accepted
time: 4ms
memory: 16336kb
input:
100 100 .................................................................................................... .........#.......................................................................................... .........................................................................................#...
output:
-1
result:
ok single line: '-1'
Test #60:
score: 0
Accepted
time: 1ms
memory: 15324kb
input:
100 100 ...........#..........................##...#....#.#..............##.....#.#..........#.......#...#.. .....#.....#...#...........#....##............#.....##................#..##.......###...#........... ..#......##.....#.#.#.....#...#.#.....#..#........................#.#.#........#.#..###..#...
output:
-1
result:
ok single line: '-1'
Test #61:
score: 0
Accepted
time: 2ms
memory: 16260kb
input:
100 100 ................##.....#........................................#...##.......#...#..S...##.......U.. ...#.....#..................................#.............###......................#................ .........#....#......#.....................................#......#.............#............
output:
-1
result:
ok single line: '-1'
Test #62:
score: 0
Accepted
time: 11ms
memory: 16776kb
input:
100 100 ..........................#........#..............#.........##.#.#....#....#...#.................... .......................#.................#..##..................#.....................#..#.#........ ...........#....................#....................#....#...................#..............
output:
17
result:
ok single line: '17'
Test #63:
score: 0
Accepted
time: 3ms
memory: 17020kb
input:
100 100 .......................................U............................................................ ............................................................................##...................... .............................................................#...............................
output:
42
result:
ok single line: '42'
Test #64:
score: 0
Accepted
time: 5ms
memory: 17744kb
input:
100 100 .................................................................................................... .................................................................................................... .............................................................................................
output:
10
result:
ok single line: '10'
Test #65:
score: 0
Accepted
time: 10ms
memory: 15828kb
input:
100 100 #........................................#.......................#.................................. ..............................................#......#..................#......................#.... ....#...........#................#......#....................................................
output:
10
result:
ok single line: '10'
Test #66:
score: 0
Accepted
time: 12ms
memory: 18296kb
input:
100 100 ...##.##......##.........#....###...#.#..#.#..##..###..#..#.#..#...#.#.........#.#.#....#.#..#.#...T ...#.#..##.#..#.#.................#..............#.#.....#........##....#....#..........#..#.#...... #.#.....#...#...#..##...................#.#..#..##.#......#..#........#.#....#...#...#.......
output:
3
result:
ok single line: '3'
Test #67:
score: 0
Accepted
time: 5ms
memory: 17932kb
input:
100 100 .............................#.......................#.............................................. ...............................................................................#.................... ......#...###.......................................................##............#..........
output:
6
result:
ok single line: '6'
Test #68:
score: 0
Accepted
time: 5ms
memory: 15880kb
input:
100 100 .......#......................#.....#.............#.....T.......#.............#..................... .....................................#..............................#...................#.......##.. ................................#....#........................#..............................
output:
7
result:
ok single line: '7'
Test #69:
score: 0
Accepted
time: 4ms
memory: 15684kb
input:
100 100 S..................................................................................................T .................................................................................................... .............................................................................................
output:
9902
result:
ok single line: '9902'
Test #70:
score: 0
Accepted
time: 1ms
memory: 15912kb
input:
100 100 S..................................................................................................T .................................................................................................... .............................................................................................
output:
9506
result:
ok single line: '9506'
Test #71:
score: 0
Accepted
time: 1ms
memory: 15896kb
input:
100 100 S..................................................................................................T .................................................................................................... .............................................................................................
output:
2280
result:
ok single line: '2280'
Test #72:
score: 0
Accepted
time: 1ms
memory: 13892kb
input:
100 100 S..................................................................................................T .................................................................................................... .............................................................................................
output:
1470
result:
ok single line: '1470'
Test #73:
score: 0
Accepted
time: 7ms
memory: 15928kb
input:
100 100 S..................................................................................................T .................................................................................................... .............................................................................................
output:
102
result:
ok single line: '102'
Test #74:
score: 0
Accepted
time: 1ms
memory: 13784kb
input:
2 3 STU ### 2 1 1 r 1 2 r
output:
-1
result:
ok single line: '-1'
Test #75:
score: 0
Accepted
time: 1ms
memory: 13748kb
input:
2 4 ST.U #### 3 1 1 r 1 2 r 1 3 r
output:
2
result:
ok single line: '2'
Test #76:
score: 0
Accepted
time: 3ms
memory: 11644kb
input:
3 5 S.U## ##.## ..T.. 4 1 1 r 1 2 r 1 3 b 2 3 b
output:
-1
result:
ok single line: '-1'
Test #77:
score: 0
Accepted
time: 3ms
memory: 11780kb
input:
10 10 ......S... .......... ##........ .....#.... .....#..## .........T U......... .......... ....#..... ....#..... 30 6 9 r 3 7 r 4 8 b 5 8 b 2 6 b 3 3 b 7 5 b 4 1 b 4 3 b 6 7 b 7 6 r 6 9 b 3 7 b 6 6 r 4 4 r 4 5 b 8 5 r 4 7 b 3 4 r 5 7 b 6 8 b 7 6 b 4 4 b 4 2 b 2 5 b 6 5 r 2 7 b 3 4 b 7 5 r 8 4 r
output:
21
result:
ok single line: '21'
Test #78:
score: 0
Accepted
time: 3ms
memory: 11684kb
input:
10 10 .......... .......... .......... .......... .......... .....#.... ##....#... U...#..#.. ####...... ST........ 25 8 9 b 7 9 r 9 8 r 6 4 r 10 1 r 3 5 b 6 9 b 9 6 b 7 9 b 4 4 r 9 8 b 4 6 r 9 5 r 8 10 b 6 4 b 5 4 r 9 10 b 7 3 r 5 6 r 6 8 b 7 4 b 8 9 r 9 9 r 3 6 b 9 7 b
output:
21
result:
ok single line: '21'