QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#94073 | #5472. Secure the Top Secret | whatever# | AC ✓ | 10ms | 5316kb | C++23 | 5.9kb | 2023-04-05 10:22:28 | 2023-04-05 10:22:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int N = 110;
namespace flow {
constexpr int V = 15010, E = 100010, inf = 1e9;
struct edge {
int to, f, w, nxt;
}e[E * 2];
int head[V], cur[V], vis[V];
int n, s, t, cnt, dis[V], h[V];
void init(int _n, int _s, int _t) {
n = _n, s = _s, t = _t, cnt = 1;
}
void add(int u, int v, int f, int w) {
e[++ cnt] = {v, f, w, head[u]}, head[u] = cnt;
e[++ cnt] = {u, 0, -w, head[v]}, head[v] = cnt;
}
bool dij() {
memcpy(cur, head, n + 1 << 2);
fill(dis, dis + n + 1, inf);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
dis[s] = 0; q.emplace(0, s);
while(!q.empty()) {
auto [d, u] = q.top(); q.pop();
if(d != dis[u]) continue;
for(int i = head[u]; i; i = e[i].nxt) {
int v = e[i].to, w = e[i].w + h[u] - h[v];
if(e[i].f && dis[v] > dis[u] + w) {
dis[v] = dis[u] + w;
q.emplace(dis[v], v);
}
}
}
return dis[t] < inf;
}
int dfs(int u, int flow) {
if(u == t) return flow;
int ret = flow; vis[u] = 1;
for(int &i = cur[u]; i; i = e[i].nxt) {
int v = e[i].to, w = e[i].w + h[u] - h[v];
if(e[i].f && dis[v] == dis[u] + w && !vis[v]) {
int k = dfs(v, min(e[i].f, ret));
ret -= k, e[i].f -= k, e[i ^ 1].f += k;
if(!ret) break;
}
}
vis[u] = 0;
return flow - ret;
}
void spfa() {
static int use[V];
memset(dis, 0x3f, n + 1 << 2);
queue<int> q;
dis[s] = 0; q.emplace(s);
while(!q.empty()) {
int u = q.front() ; q.pop(); use[u] = 0;
for(int i = head[u]; i; i = e[i].nxt) {
int v = e[i].to;
i64 w = e[i].w;
if(e[i].f && dis[v] > dis[u] + w) {
dis[v] = dis[u] + w;
if(!use[v]) q.emplace(v), use[v] = 1;
}
}
}
}
pair<int, int> mincostmaxflow() {
int flow = 0, cost = 0;
while(dij()) {
int ret = dfs(s, INT_MAX);
for(int i = 0; i <= n; i ++) if(dis[i] < dis[0]) {
h[i] += dis[i];
}
flow += ret;
cost += ret * h[t];
if(flow >= 2) break;
}
return {flow, cost};
}
}
int n, m, id[N][N];
int banR[N][N], banC[N][N];
int bad[N][N];
string str[N];
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i ++) {
cin >> str[i];
for(int j = 0; j < m; j ++) {
if(str[i][j] == '#') {
banR[i][j] = 2;
banR[i][j + 1] = 2;
banC[i][j] = 2;
banC[i + 1][j] = 2;
}
}
}
int tot = 0;
for(int i = 0; i <= n; i ++) {
for(int j = 0; j <= m; j ++) {
id[i][j] = tot ++;
}
}
int k; cin >> k;
for(int i = 0; i < k; i ++) {
int r, c; char o;
cin >> r >> c >> o;
r --, c --;
if(o == 'r') banR[r][c + 1] = 1;
if(o == 'b') banC[r + 1][c] = 1;
}
vector<pair<int, int>> pos;
for(int i = 0; i < n; i ++) pos.emplace_back(i, 0);
for(int i = 1; i < m; i ++) pos.emplace_back(n - 1, i);
for(int i = n - 2; i >= 0; i --) pos.emplace_back(i, m - 1);
for(int i = m - 2; i > 0; i --) pos.emplace_back(0, i);
rotate(pos.begin(), find_if(pos.begin(), pos.end(), [&] (auto p) {return str[p.first][p.second] == 'T';}), pos.end());
auto trans = [&] (int x, int y) -> pair<int, int> {
if(x == 0 && y == 0) return {x + 1, y};
if(x == n - 1 && y == 0) return {x + 1, y + 1};
if(x == n - 1 && y == m - 1) return {x, y + 1};
if(x == 0 && y == m - 1) return {x, y};
if(x == 0) return {x, y};
if(y == 0) return {x + 1, y};
if(x == n - 1) return {x + 1, y + 1};
if(y == m - 1) return {x, y + 1};
assert(false);
};
int p, q;
for(int i = 0; i < pos.size(); i ++) {
auto [x, y] = pos[i];
if(str[x][y] == 'S') {
p = i;
}
if(str[x][y] == 'U') {
q = i;
}
}
flow::init(tot + 1, tot, tot + 1);
auto bfs = [&] (int x, int y) {
static int vis[N][N];
queue<pair<int, int>> q;
q.emplace(x, y); vis[x][y] = 1;
while(!q.empty()) {
auto [x, y] = q.front(); q.pop();
bad[x][y] =1;
bad[x + 1][y] = 1;
bad[x][y + 1] = 1;
bad[x + 1][y + 1] = 1;
for(auto dir : {array<int, 2> {0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}}) {
int dx = x + dir[0], dy = y + dir[1];
if(dx >= 0 && dx < n && dy >= 0 && dy < m && str[dx][dy] == '#' && !vis[dx][dy]) {
q.emplace(dx, dy);
vis[dx][dy] = 1;
}
}
}
};
if(p < q) {
for(int i = p; i < q; i ++) {
auto [x, y] = trans(pos[i].first, pos[i].second);
flow::add(flow::s, id[x][y], 2, 0);
}
for(int i = q; i < pos.size(); i ++) {
auto [x, y] = trans(pos[i].first, pos[i].second);
flow::add(id[x][y], flow::t, 2, 0);
}
for(int i = 0; i < p; i ++) {
auto [x, y] = pos[i];
if(str[x][y] == '#') {
bfs(x, y);
} else {
tie(x, y) = trans(x, y);
bad[x][y] = 1;
}
}
} else {
for(int i = q; i < p; i ++) {
auto [x, y] = trans(pos[i].first, pos[i].second);
flow::add(flow::s, id[x][y], 2, 0);
}
for(int i = 0; i < q; i ++) {
auto [x, y] = trans(pos[i].first, pos[i].second);
flow::add(id[x][y], flow::t, 2, 0);
}
for(int i = p; i < pos.size(); i ++) {
auto [x, y] = pos[i];
if(str[x][y] == '#') {
bfs(x, y);
} else {
tie(x, y) = trans(x, y);
bad[x][y] = 1;
}
}
}
for(int i = 0; i < n; i ++) {
for(int j = 0; j <= m; j ++) {
if(banR[i][j] && !bad[i][j] && !bad[i + 1][j]) {
flow::add(id[i][j], id[i + 1][j], 1 + (banR[i][j] == 2), banR[i][j] == 1);
flow::add(id[i + 1][j], id[i][j], 1 + (banR[i][j] == 2), banR[i][j] == 1);
}
}
}
for(int i = 0; i <= n; i ++) {
for(int j = 0; j < m; j ++) {
if(banC[i][j] && !bad[i][j] && !bad[i][j + 1]) {
flow::add(id[i][j], id[i][j + 1], 1 + (banC[i][j] == 2), banC[i][j] == 1);
flow::add(id[i][j + 1], id[i][j], 1 + (banC[i][j] == 2), banC[i][j] == 1);
}
}
}
auto [flow, cost] = flow::mincostmaxflow();
cout << (flow < 2 ? -1 : cost) << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
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: 2ms
memory: 3604kb
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: 0ms
memory: 3476kb
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: 1ms
memory: 3564kb
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: 2ms
memory: 3468kb
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: 2ms
memory: 3492kb
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: 2ms
memory: 3468kb
input:
3 3 UST ### .#. 2 1 1 r 1 2 r
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3552kb
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: 0ms
memory: 3528kb
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: 2ms
memory: 3620kb
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: 2ms
memory: 3572kb
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: 2ms
memory: 3456kb
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: 0ms
memory: 3492kb
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: 3ms
memory: 3768kb
input:
97 97 S...............................................................................................T ................................................................................................. ................................................................................................. ...
output:
130
result:
ok single line: '130'
Test #15:
score: 0
Accepted
time: 3ms
memory: 3892kb
input:
100 94 S............................................................................................T .............................................................................................. .............................................................................................. ...........
output:
126
result:
ok single line: '126'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
95 92 S..........................................................................................T ............................................................................................ ............................................................................................ ..................
output:
124
result:
ok single line: '124'
Test #17:
score: 0
Accepted
time: 2ms
memory: 3948kb
input:
92 92 S..........................................................................................T ............................................................................................ ............................................................................................ ..................
output:
124
result:
ok single line: '124'
Test #18:
score: 0
Accepted
time: 0ms
memory: 4040kb
input:
96 100 S..................................................................................................T .................................................................................................... ..............................................................................................
output:
134
result:
ok single line: '134'
Test #19:
score: 0
Accepted
time: 1ms
memory: 4004kb
input:
92 90 S........................................................................................T .......................................................................................... .......................................................................................... ........................
output:
120
result:
ok single line: '120'
Test #20:
score: 0
Accepted
time: 2ms
memory: 3896kb
input:
96 90 S........................................................................................T .......................................................................................... .......................................................................................... ........................
output:
120
result:
ok single line: '120'
Test #21:
score: 0
Accepted
time: 3ms
memory: 4044kb
input:
92 94 S............................................................................................T .............................................................................................. .............................................................................................. ............
output:
126
result:
ok single line: '126'
Test #22:
score: 0
Accepted
time: 3ms
memory: 4080kb
input:
99 94 S............................................................................................T .............................................................................................. .............................................................................................. ............
output:
126
result:
ok single line: '126'
Test #23:
score: 0
Accepted
time: 3ms
memory: 4072kb
input:
93 91 S.........................................................................................T ........................................................................................... ........................................................................................... .....................
output:
122
result:
ok single line: '122'
Test #24:
score: 0
Accepted
time: 0ms
memory: 4232kb
input:
50 83 ........................#.............................#........#......#.....#...... ...........................................#........#................#........#.... ....................#.....#........................................................ ................................#............
output:
22
result:
ok single line: '22'
Test #25:
score: 0
Accepted
time: 2ms
memory: 3956kb
input:
58 98 .........#.....#...U............#..............#.......#....................##...........#........ .........#........#.....#...#..#........#.#.........#..................#.#........................ .#.##.......#........#......#..#.....#.........#..#.........#...##.........###..##......#..........
output:
-1
result:
ok single line: '-1'
Test #26:
score: 0
Accepted
time: 3ms
memory: 4252kb
input:
80 48 ..##.#.........#...#.....#............#.#.#.#... ....#........#.......#...#.##.#.##....#.##.#...# #......##.#..#.......#.....##..#..#.......##.#.# .##.#...#.#.#.#.....###...#......#............## .....#.#.....#.#..##.......##..#...#.#..#..##... .......#....#.#...##.##.##....#...#......#..#### ...
output:
2
result:
ok single line: '2'
Test #27:
score: 0
Accepted
time: 3ms
memory: 3816kb
input:
40 49 #.....................#..................#....... ..................#......#....#..#....#.#.......U ......#.................................#........ ................................................. #.......#.......#..........#..................... ....#.......#.......#............#.............
output:
9
result:
ok single line: '9'
Test #28:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
25 39 .......................#............... ...................................#... ....................................... ##.......................#............. ..................#.........#.......... ..#...................................U ...............................#....... .................
output:
-1
result:
ok single line: '-1'
Test #29:
score: 0
Accepted
time: 2ms
memory: 3696kb
input:
17 47 ..#.....#...#...#........................T.#... .........................#.........#......#.... .....#..........##..#.......#...#........#..... ......#.......................#................ ##...#........#.......##.#.#.......#.##........ ............................................... #..#.....
output:
-1
result:
ok single line: '-1'
Test #30:
score: 0
Accepted
time: 2ms
memory: 3632kb
input:
18 66 ...#..#...#..#.#...#U#.#....##...#.#.#.......#.#..........#......# ....##...#...##..##.....#..#.##.#..##...........#....#.....#...#.# #...##..........##.....#........#...##.#.##............#.#...#.#.. #.#..#..#........#..#....#...#..#.....##..#..#..............#....# .........#...##.#..#.#.###...
output:
4
result:
ok single line: '4'
Test #31:
score: 0
Accepted
time: 2ms
memory: 4392kb
input:
69 81 .....#..........#.##..U....#..#.S#....#..###..##...........#....##..####.#T.##.## ##........##...##.#.#.##...#.###.#...#....##..#...#..###.....#.................#. .......##...###..#....#..###.....#..##...#....#..#..#...#.#...#.#....#...##...#.# #...#...........##..###.#.#.##.#...#.#....#..#.#...
output:
2
result:
ok single line: '2'
Test #32:
score: 0
Accepted
time: 3ms
memory: 4116kb
input:
87 26 .##....#.U.#.#.#......#... ...#...##..#...#.##...#..T #..........#...#.....#.#.. ##.#..##...##.#..#..#..... ................##.....##. ......###..##.#..#..#..... ...#.....#....##..#....... #.......###..#.....#...... ######..##......#.....#... #.#.#....#.#.........#..#. .#.....#..###..#......#....
output:
4
result:
ok single line: '4'
Test #33:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
19 92 .#....#.#.....#.#.........###..S##.#...#..#.#..#...#..####.......#.......#...#.##.##...##... .......#.#.#.#..#...#..###..#...#..#....#......##........#.#.........#..#.###....#.....#.... ......#...#..#.#...#.....##..##......##.###....#...#....#.#.###..#...#####.##..#....#..#.### .##...##.#.#..#...
output:
2
result:
ok single line: '2'
Test #34:
score: 0
Accepted
time: 0ms
memory: 4452kb
input:
92 96 ...#..##.#..##.......#.....#..#.#S#....#.........##...#.#..#...#.......#..#............#..#..#.. ...#.#.#.#....#.##....#....#.#....#...#...#....#..##....#..#....#...#..#....#....##....#..#..... .#...#..#.........#..........#.##.#..#..#.#..#..#.....#.#....#.#.#..........##.......#.#....##.. ......
output:
-1
result:
ok single line: '-1'
Test #35:
score: 0
Accepted
time: 7ms
memory: 4980kb
input:
90 90 ##....#........#..#..#.#...#...#.#....#.#....##..#.#......#...#......T.#..####........#.#. ..#...............#.#...#...#......#.......#.#..#.#.......#...#.....##....#..##.....#..... .###.......##.##.........#.#.#..##.##..#........#.#......#......#.#.#..###..##..#.#.....#. ..##......#.........#...
output:
6
result:
ok single line: '6'
Test #36:
score: 0
Accepted
time: 0ms
memory: 4460kb
input:
98 93 ..#...........##..........##.#......#....#.....#.......#..#.#.#.......#..................U.#. ..#........#..#..#...#...##.................#.#........#.......##.#..#..#.....#.......#.###.# ...........###..#####.#..##.......#.#........#.#.....#.......#......#....#..#..#............. #...#.#........
output:
-1
result:
ok single line: '-1'
Test #37:
score: 0
Accepted
time: 4ms
memory: 4488kb
input:
96 97 #............#.................#....#.#.#...#....#..###..#.#....#.##...#..#...........#.......... ..#.........##........#...#.##....##....###...#.###..#.#..............##.#.....................#. ..#..........#.#.#..#...........#...##............#......##...................#......##....#..... ...
output:
-1
result:
ok single line: '-1'
Test #38:
score: 0
Accepted
time: 0ms
memory: 4748kb
input:
91 94 #...........#.#.##.#..#.....#.#........S.##.......##....#..#........#..#...#..#..#........#U#. ...#.....#..#.....##.#..#.##....#...#.##....#....#......##.#.#............##.......#....#....# #..#...#..#...#.#..###.#...#....#..##....#....##....#.#.##.........#..#...#.#........#.#.#..## ....##......
output:
4
result:
ok single line: '4'
Test #39:
score: 0
Accepted
time: 4ms
memory: 4556kb
input:
94 91 ...........#......#...#.....#..###.....#.......#....##.#....#........#......####.......#... ..#...###...##.......#..#....#..#.###.#....#......#.#..####.##...#...#..##..#.#...###..#... ..#.#.##..#...........#.........#.#.......#...........#.###......#..#....#......#...#...... .#.....##..#.....#...
output:
21
result:
ok single line: '21'
Test #40:
score: 0
Accepted
time: 6ms
memory: 4684kb
input:
90 94 ##..........#.#.#.....#.....#..#..#......#.#..##..##....##..#.#.#..#.###.#...#.........T.#.... ....#.#.....#.#...............##..#..##.##.#..#....##....###.#.#.#...#..###.........#.##....## ...##.............#..#.....#..#..#.......#....#...###....#.#..#...#.#....#...###..####........ #..##...#...
output:
24
result:
ok single line: '24'
Test #41:
score: 0
Accepted
time: 3ms
memory: 4184kb
input:
93 98 .............#.........#.....U..#......................##......................................... ...........#............#...........................................................###...#....... ....................................................................................#..............
output:
-1
result:
ok single line: '-1'
Test #42:
score: 0
Accepted
time: 6ms
memory: 4768kb
input:
96 100 ..........#........#..#...#..#.........#....#....#.#.....##......##....##............#.............# .......#.#..#.#.#..#....................#..............##.....#.........#...#...#.....#.....#.....#. ##.....##.#.###...#...#.#.............###.#.......#.#................#........#........##.....
output:
12
result:
ok single line: '12'
Test #43:
score: 0
Accepted
time: 7ms
memory: 4828kb
input:
100 99 ................#..#............T.....#.....#.....#............#.#.....U.#..#.....#..........#..... .................................#.#............................................................... ............#..........#..#..#.........#...................#............................#.......
output:
100
result:
ok single line: '100'
Test #44:
score: 0
Accepted
time: 2ms
memory: 3672kb
input:
13 22 ..#...#U#......#....## ......##.............# ......#....#...#.....# .........#..#......... ...................#.. ......###.........#..# ....#..............#.T .#..#...#............. #.....#.....##...#.... .#.........#.##....... ......#..#............ .#.....#...#...#...... ..S..#.#.............
output:
0
result:
ok single line: '0'
Test #45:
score: 0
Accepted
time: 1ms
memory: 4036kb
input:
84 35 ...#.#.#.......###..#......##.###.. ...#....##.#..##......###.#..#.##.. ...###.....#..###.#..#.#..#...#...# #...###.#..#..#....#...#.#.#.....#. ###...##......#.##.#.....#...#.#..# ...#.#...###......#.....#....#....# #.#..##.##.###...#..###....##.##... ###..#.#........#...#.#.##.#.#..... ...#.....
output:
0
result:
ok single line: '0'
Test #46:
score: 0
Accepted
time: 2ms
memory: 3596kb
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: 2ms
memory: 4352kb
input:
85 67 ...##....##..#..#....##..##S.##...#....#.#............#............ .......#.#..#....#..#..#.#...##..##.#...#.#.#...#......#.....##..#. ..#.....#.....#.#.......#.....#.......#..#.###..#.........#........ ##.#.#.#.#.###.#..........##....#.....#.#..##.#...........#...###.# ...........#.......#.....
output:
0
result:
ok single line: '0'
Test #48:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
42 30 ##.....##.#.#T.#.#.#.#....#.#. ..#.......##...#.#.#...#...... #.........#...#.##....#..#.... .....#..#....#..#...##...####. #.......###...#..#......#..#.. ...#.....#......#..#......#.## ##.#.#.#..#...#.......####.... ....#...##.....#....#.#.#..... ........#..#.#......#....#.#.. .#.##.#...###.....
output:
0
result:
ok single line: '0'
Test #49:
score: 0
Accepted
time: 2ms
memory: 4232kb
input:
62 62 ..........##...#.#.............#.#..........#................. ...............#.#............#..........................#.... ...................#.........................##............... ........#............#..................#................#.... ..........................#..#.......##......
output:
8
result:
ok single line: '8'
Test #50:
score: 0
Accepted
time: 5ms
memory: 4624kb
input:
89 74 ...#....#.#....#...........#..#T.#....................##.U.............##. ...##.....#......##......................#....#.#..#....#..#........##.... ...#.##............#...#.........#........#.#..........##.#..#............ .#.......#.....#.....#..#..............##.#................#............
output:
4
result:
ok single line: '4'
Test #51:
score: 0
Accepted
time: 0ms
memory: 4208kb
input:
100 37 .....................#..#.........#.. .............#........#........#..... ...........#......................... ..##..#.....#.............#.......... ............#..................#..... #..#................##...#........... ..#...........#...#.................. ..................#.#.....#...
output:
6
result:
ok single line: '6'
Test #52:
score: 0
Accepted
time: 1ms
memory: 4256kb
input:
44 89 ...#.#.#...##.#.#.....#..##..#.#......##.........#..##....#.....##....##.#.........#..#.. ##....##.#...........#...#..##.#....#...#.#.#......#........#..#..........#.......##....# ....#..#...#.#......#.#...###.#......#....#.#.#......#...##..............##.#.##...#..#.. .#.....###.#..#...#..#.....
output:
4
result:
ok single line: '4'
Test #53:
score: 0
Accepted
time: 2ms
memory: 3880kb
input:
68 17 ##.....#....#.... .#.##...#...#...# ...#....#....##.. ..#...#........#. ..#..####.#...##. .....###......... .#.........#..#.# ....#.#.#.#.....# ...#.....#....... #..#.###...####.. ..##.##....#.#... ##.....#.#.....#. ....#....#......# ..##............. .....#.........#. ....#...........# ..##.....
output:
6
result:
ok single line: '6'
Test #54:
score: 0
Accepted
time: 2ms
memory: 3672kb
input:
16 23 ..#..##.#U.#...#....#.# ...#...##.##.#...##...# ...#.#..#..##.#..#.#... ...#..#.#.#..#....#...# ##..#..#........#...... .......#.#.#........#.. .#.....#...#..#.#...... ........#..###.....###. .##.......#.###..##.#.. .....#..######......#.. #..#....#....#.#....#.# ....#.#..#....##....##. .#.#.....
output:
-1
result:
ok single line: '-1'
Test #55:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
43 67 .............#....#.............................S.#............#... ..........#.................#.............#........................ ................................#................................#. .........................#..........#...........#.................. ....#....................
output:
-1
result:
ok single line: '-1'
Test #56:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
79 22 .#......#..#...#.#...# ............#......... .###.......#.#..#....# ..#..#...........##... ......#.....###....#.# #.......#..#........#. .....#.....#.......... ......#.#.#.......#... ....#......##..#....#. ...#...#......##...... .....#...#.#..###..... .....###.......#...... #...........#..#.....
output:
-1
result:
ok single line: '-1'
Test #57:
score: 0
Accepted
time: 2ms
memory: 3492kb
input:
9 18 ...#...#....#....# .........##....... ..#.....#.#..###.U ...#..#..####...#T .#.###.##.......#. ......#....####.#. #....#....##.#..## S............#.#.. ###..#....#...#..# 0
output:
-1
result:
ok single line: '-1'
Test #58:
score: 0
Accepted
time: 2ms
memory: 3876kb
input:
40 72 #...#...#......#.#.#....#.##..##.#..##.#####..#.##...###.#.####..##..... .###.#..#.......#..#..#..#.#.#....##.....#..###.#..#.##..#.#.#....#....# ..#.#..#..#..#....#..####....#.#....##............#..#...##..#.#.#..#..# ####..#.##.....#..#........#.#......#...#..###.......##..#.............. .....
output:
-1
result:
ok single line: '-1'
Test #59:
score: 0
Accepted
time: 4ms
memory: 4560kb
input:
100 100 .................................................................................................... .........#.......................................................................................... .........................................................................................#...
output:
-1
result:
ok single line: '-1'
Test #60:
score: 0
Accepted
time: 1ms
memory: 4360kb
input:
100 100 ...........#..........................##...#....#.#..............##.....#.#..........#.......#...#.. .....#.....#...#...........#....##............#.....##................#..##.......###...#........... ..#......##.....#.#.#.....#...#.#.....#..#........................#.#.#........#.#..###..#...
output:
-1
result:
ok single line: '-1'
Test #61:
score: 0
Accepted
time: 1ms
memory: 4580kb
input:
100 100 ................##.....#........................................#...##.......#...#..S...##.......U.. ...#.....#..................................#.............###......................#................ .........#....#......#.....................................#......#.............#............
output:
-1
result:
ok single line: '-1'
Test #62:
score: 0
Accepted
time: 7ms
memory: 4716kb
input:
100 100 ..........................#........#..............#.........##.#.#....#....#...#.................... .......................#.................#..##..................#.....................#..#.#........ ...........#....................#....................#....#...................#..............
output:
17
result:
ok single line: '17'
Test #63:
score: 0
Accepted
time: 5ms
memory: 4768kb
input:
100 100 .......................................U............................................................ ............................................................................##...................... .............................................................#...............................
output:
42
result:
ok single line: '42'
Test #64:
score: 0
Accepted
time: 10ms
memory: 5208kb
input:
100 100 .................................................................................................... .................................................................................................... .............................................................................................
output:
10
result:
ok single line: '10'
Test #65:
score: 0
Accepted
time: 10ms
memory: 5292kb
input:
100 100 #........................................#.......................#.................................. ..............................................#......#..................#......................#.... ....#...........#................#......#....................................................
output:
10
result:
ok single line: '10'
Test #66:
score: 0
Accepted
time: 6ms
memory: 5240kb
input:
100 100 ...##.##......##.........#....###...#.#..#.#..##..###..#..#.#..#...#.#.........#.#.#....#.#..#.#...T ...#.#..##.#..#.#.................#..............#.#.....#........##....#....#..........#..#.#...... #.#.....#...#...#..##...................#.#..#..##.#......#..#........#.#....#...#...#.......
output:
3
result:
ok single line: '3'
Test #67:
score: 0
Accepted
time: 10ms
memory: 5316kb
input:
100 100 .............................#.......................#.............................................. ...............................................................................#.................... ......#...###.......................................................##............#..........
output:
6
result:
ok single line: '6'
Test #68:
score: 0
Accepted
time: 10ms
memory: 5312kb
input:
100 100 .......#......................#.....#.............#.....T.......#.............#..................... .....................................#..............................#...................#.......##.. ................................#....#........................#..............................
output:
7
result:
ok single line: '7'
Test #69:
score: 0
Accepted
time: 1ms
memory: 5204kb
input:
100 100 S..................................................................................................T .................................................................................................... .............................................................................................
output:
9902
result:
ok single line: '9902'
Test #70:
score: 0
Accepted
time: 2ms
memory: 5196kb
input:
100 100 S..................................................................................................T .................................................................................................... .............................................................................................
output:
9506
result:
ok single line: '9506'
Test #71:
score: 0
Accepted
time: 5ms
memory: 4740kb
input:
100 100 S..................................................................................................T .................................................................................................... .............................................................................................
output:
2280
result:
ok single line: '2280'
Test #72:
score: 0
Accepted
time: 5ms
memory: 4592kb
input:
100 100 S..................................................................................................T .................................................................................................... .............................................................................................
output:
1470
result:
ok single line: '1470'
Test #73:
score: 0
Accepted
time: 2ms
memory: 4428kb
input:
100 100 S..................................................................................................T .................................................................................................... .............................................................................................
output:
102
result:
ok single line: '102'
Test #74:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
2 3 STU ### 2 1 1 r 1 2 r
output:
-1
result:
ok single line: '-1'
Test #75:
score: 0
Accepted
time: 0ms
memory: 3460kb
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: 2ms
memory: 3556kb
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: 0ms
memory: 3612kb
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: 2ms
memory: 3636kb
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'