QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95472#5472. Secure the Top SecretwhateverAC ✓12ms6200kbC++144.7kb2023-04-09 19:58:292023-04-09 19:58:30

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-09 19:58:30]
  • 评测
  • 测评结果:AC
  • 用时:12ms
  • 内存:6200kb
  • [2023-04-09 19:58:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = a, I = b; i <= I; ++i)
#define per(i, a, b) for (int i = a, I = b; i >= I; --i)

const int inf = 1e9;

namespace flow {
    const int N = 12000;
    int n, s, t, dis[N], h[N], prv[N];
    struct edge {
        int to, cap, cost;
    };
    vector<edge> E;
    vector<int> e[N];

    void add(int u, int v, int cap, int cost) {
        e[u].push_back(E.size()), E.push_back({v, cap, cost});
        e[v].push_back(E.size()), E.push_back({u, 0, -cost});
    }
    void dij() {
        memset(dis, 0x3f, sizeof dis);
        dis[s] = 0;
        priority_queue<pii, vector<pii>, greater<pii>> pq;
        pq.push({0, s});
        while (!pq.empty()) {
            auto cur = pq.top(); pq.pop();
            int u = cur.second;
            for (auto i : e[u]) {
                auto [v, cap, cost] = E[i];
                if (!cap) continue;
                cost += h[u] - h[v];
                if (dis[v] > dis[u] + cost) {
                    dis[v] = dis[u] + cost, prv[v] = i;
                    pq.push({dis[v], v});
                }
            }
        }
    }
    int solve(int lim) {
        int ans = 0;
        while (lim--) {
            dij();
            if (dis[t] >= inf) return -1;
            ans += dis[t];
            int u = t;
            while (u != s) {
                --E[prv[u]].cap;
                ++E[prv[u] ^ 1].cap;
                u = E[prv[u] ^ 1].to;
            }
        }
        return ans;
    }
}

const int N = 105;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int n, m, px[N * 4], py[N * 4], qx[N * 4], qy[N * 4];
char s[N][N];
bool valid_r[N][N], valid_b[N][N], free_r[N][N], free_b[N][N];
vector<pair<int, int>> e[N * N];
bool banned[N * N];

int ID(int x, int y) {
    if (x == 1) return y;
    if (y == m) return m + x - 1;
    if (x == n) return n + m - 1 + m - y;
    if (y == 1) return n + 2 * m - 2 + n - x;
    return 0;
}
bool is_normal(int i, int j) {
    return s[i][j] == '.' || s[i][j] == '#';
}
int idx(int i, int j) {
    return i * (m + 1) + j;
}
void add_edge(int u, int v, int w) {
    e[u].push_back({v, w});
    e[v].push_back({u, w});
}

int main() {
    // freopen("1.in", "r", stdin);
    ios::sync_with_stdio(0), cin.tie(0);

    cin >> n >> m;
    rep(i, 1, n) cin >> (s[i] + 1);
    int k; cin >> k;
    while (k--) {
        int x, y; char op;
        cin >> x >> y >> op;
        (op == 'b' ? valid_b : valid_r)[x][y] = true;
    }
    
    rep(i, 1, n) rep(j, 1, m) {
        int id = ID(i, j);
        if (!id) continue;
        px[id] = i, py[id] = j;
        qx[id] = px[id], qy[id] = py[id];
        if (id <= m - 1) --qx[id];
        else if (id <= n + m - 2);
        else if (id <= n + 2 * m - 3) --qy[id];
        else --qy[id], --qx[id];
    }

    vector<int> st, su, tu;
    int cnt = 2 * (n + m) - 4;
    rep(i, 1, cnt) {
        char prv, nxt;
        {
            int j = i;
            while (is_normal(px[j], py[j])) j = (j == 1 ? cnt : (j - 1));
            prv = s[px[j]][py[j]];
        }
        {
            int j = (i == cnt ? 1 : (i + 1));
            while (is_normal(px[j], py[j])) j = (j == cnt ? 1 : (j + 1));
            nxt = s[px[j]][py[j]];
        }
        if (prv > nxt) swap(prv, nxt);
        int cur = idx(qx[i], qy[i]);
        if (prv == 'S' && nxt == 'T') st.push_back(cur);
        else if (prv == 'S' && nxt == 'U') su.push_back(cur);
        else tu.push_back(cur);
    }

    rep(i, 1, n) rep(j, 1, m) {
        if (!is_normal(i, j)) continue;
        if (s[i][j] == '#') {
            valid_r[i][j] = valid_r[i][j - 1] = free_r[i][j] = free_r[i][j - 1] = true;
            valid_b[i][j] = valid_b[i - 1][j] = free_b[i][j] = free_b[i - 1][j] = true;
        }
    }
    rep(i, 1, n) rep(j, 1, m) {
        if (valid_r[i][j]) add_edge(idx(i - 1, j), idx(i, j), !free_r[i][j]);
        if (valid_b[i][j]) add_edge(idx(i, j - 1), idx(i, j), !free_b[i][j]);
    }

    flow::n = flow::t = (n + 1) * (m + 1) + 1;
    queue<int> que;
    auto push = [&](int u) {
        if (banned[u]) return;
        banned[u] = true, que.push(u);
    };
    for (auto u : st) push(u);
    while (!que.empty()) {
        int u = que.front(); que.pop();
        for (auto [v, w] : e[u]) if (!w) push(v);
    }

    for (auto u : su) flow::add(flow::s, u, inf, 0);
    for (auto u : tu) flow::add(u, flow::t, inf, 0);
    rep(u, 1, flow::n - 1) {
        if (banned[u]) continue;
        for (auto [v, w] : e[u]) {
            if (banned[v]) continue;
            flow::add(u, v, 1, w);
        }
    }

    int ans = flow::solve(2);
    cout << ans << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 4124kb

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: 4008kb

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: 2ms
memory: 4076kb

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: 0ms
memory: 4000kb

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: 3996kb

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: 0ms
memory: 4080kb

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: 4008kb

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: 4008kb

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: 4056kb

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: 1ms
memory: 4000kb

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: 3992kb

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: 0ms
memory: 4112kb

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: 2ms
memory: 4080kb

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: 4172kb

input:

97 97
S...............................................................................................T
.................................................................................................
.................................................................................................
...

output:

130

result:

ok single line: '130'

Test #15:

score: 0
Accepted
time: 3ms
memory: 4264kb

input:

100 94
S............................................................................................T
..............................................................................................
..............................................................................................
...........

output:

126

result:

ok single line: '126'

Test #16:

score: 0
Accepted
time: 3ms
memory: 4276kb

input:

95 92
S..........................................................................................T
............................................................................................
............................................................................................
..................

output:

124

result:

ok single line: '124'

Test #17:

score: 0
Accepted
time: 3ms
memory: 4420kb

input:

92 92
S..........................................................................................T
............................................................................................
............................................................................................
..................

output:

124

result:

ok single line: '124'

Test #18:

score: 0
Accepted
time: 0ms
memory: 4320kb

input:

96 100
S..................................................................................................T
....................................................................................................
..............................................................................................

output:

134

result:

ok single line: '134'

Test #19:

score: 0
Accepted
time: 0ms
memory: 4380kb

input:

92 90
S........................................................................................T
..........................................................................................
..........................................................................................
........................

output:

120

result:

ok single line: '120'

Test #20:

score: 0
Accepted
time: 3ms
memory: 4364kb

input:

96 90
S........................................................................................T
..........................................................................................
..........................................................................................
........................

output:

120

result:

ok single line: '120'

Test #21:

score: 0
Accepted
time: 2ms
memory: 4360kb

input:

92 94
S............................................................................................T
..............................................................................................
..............................................................................................
............

output:

126

result:

ok single line: '126'

Test #22:

score: 0
Accepted
time: 3ms
memory: 4428kb

input:

99 94
S............................................................................................T
..............................................................................................
..............................................................................................
............

output:

126

result:

ok single line: '126'

Test #23:

score: 0
Accepted
time: 3ms
memory: 4500kb

input:

93 91
S.........................................................................................T
...........................................................................................
...........................................................................................
.....................

output:

122

result:

ok single line: '122'

Test #24:

score: 0
Accepted
time: 5ms
memory: 4456kb

input:

50 83
........................#.............................#........#......#.....#......
...........................................#........#................#........#....
....................#.....#........................................................
................................#............

output:

22

result:

ok single line: '22'

Test #25:

score: 0
Accepted
time: 3ms
memory: 4372kb

input:

58 98
.........#.....#...U............#..............#.......#....................##...........#........
.........#........#.....#...#..#........#.#.........#..................#.#........................
.#.##.......#........#......#..#.....#.........#..#.........#...##.........###..##......#..........

output:

-1

result:

ok single line: '-1'

Test #26:

score: 0
Accepted
time: 5ms
memory: 4484kb

input:

80 48
..##.#.........#...#.....#............#.#.#.#...
....#........#.......#...#.##.#.##....#.##.#...#
#......##.#..#.......#.....##..#..#.......##.#.#
.##.#...#.#.#.#.....###...#......#............##
.....#.#.....#.#..##.......##..#...#.#..#..##...
.......#....#.#...##.##.##....#...#......#..####
...

output:

2

result:

ok single line: '2'

Test #27:

score: 0
Accepted
time: 4ms
memory: 4316kb

input:

40 49
#.....................#..................#.......
..................#......#....#..#....#.#.......U
......#.................................#........
.................................................
#.......#.......#..........#.....................
....#.......#.......#............#.............

output:

9

result:

ok single line: '9'

Test #28:

score: 0
Accepted
time: 0ms
memory: 4080kb

input:

25 39
.......................#...............
...................................#...
.......................................
##.......................#.............
..................#.........#..........
..#...................................U
...............................#.......
.................

output:

-1

result:

ok single line: '-1'

Test #29:

score: 0
Accepted
time: 3ms
memory: 4196kb

input:

17 47
..#.....#...#...#........................T.#...
.........................#.........#......#....
.....#..........##..#.......#...#........#.....
......#.......................#................
##...#........#.......##.#.#.......#.##........
...............................................
#..#.....

output:

-1

result:

ok single line: '-1'

Test #30:

score: 0
Accepted
time: 0ms
memory: 4252kb

input:

18 66
...#..#...#..#.#...#U#.#....##...#.#.#.......#.#..........#......#
....##...#...##..##.....#..#.##.#..##...........#....#.....#...#.#
#...##..........##.....#........#...##.#.##............#.#...#.#..
#.#..#..#........#..#....#...#..#.....##..#..#..............#....#
.........#...##.#..#.#.###...

output:

4

result:

ok single line: '4'

Test #31:

score: 0
Accepted
time: 6ms
memory: 4900kb

input:

69 81
.....#..........#.##..U....#..#.S#....#..###..##...........#....##..####.#T.##.##
##........##...##.#.#.##...#.###.#...#....##..#...#..###.....#.................#.
.......##...###..#....#..###.....#..##...#....#..#..#...#.#...#.#....#...##...#.#
#...#...........##..###.#.#.##.#...#.#....#..#.#...

output:

2

result:

ok single line: '2'

Test #32:

score: 0
Accepted
time: 2ms
memory: 4380kb

input:

87 26
.##....#.U.#.#.#......#...
...#...##..#...#.##...#..T
#..........#...#.....#.#..
##.#..##...##.#..#..#.....
................##.....##.
......###..##.#..#..#.....
...#.....#....##..#.......
#.......###..#.....#......
######..##......#.....#...
#.#.#....#.#.........#..#.
.#.....#..###..#......#....

output:

4

result:

ok single line: '4'

Test #33:

score: 0
Accepted
time: 4ms
memory: 4356kb

input:

19 92
.#....#.#.....#.#.........###..S##.#...#..#.#..#...#..####.......#.......#...#.##.##...##...
.......#.#.#.#..#...#..###..#...#..#....#......##........#.#.........#..#.###....#.....#....
......#...#..#.#...#.....##..##......##.###....#...#....#.#.###..#...#####.##..#....#..#.###
.##...##.#.#..#...

output:

2

result:

ok single line: '2'

Test #34:

score: 0
Accepted
time: 3ms
memory: 4936kb

input:

92 96
...#..##.#..##.......#.....#..#.#S#....#.........##...#.#..#...#.......#..#............#..#..#..
...#.#.#.#....#.##....#....#.#....#...#...#....#..##....#..#....#...#..#....#....##....#..#.....
.#...#..#.........#..........#.##.#..#..#.#..#..#.....#.#....#.#.#..........##.......#.#....##..
......

output:

-1

result:

ok single line: '-1'

Test #35:

score: 0
Accepted
time: 6ms
memory: 5232kb

input:

90 90
##....#........#..#..#.#...#...#.#....#.#....##..#.#......#...#......T.#..####........#.#.
..#...............#.#...#...#......#.......#.#..#.#.......#...#.....##....#..##.....#.....
.###.......##.##.........#.#.#..##.##..#........#.#......#......#.#.#..###..##..#.#.....#.
..##......#.........#...

output:

6

result:

ok single line: '6'

Test #36:

score: 0
Accepted
time: 1ms
memory: 5024kb

input:

98 93
..#...........##..........##.#......#....#.....#.......#..#.#.#.......#..................U.#.
..#........#..#..#...#...##.................#.#........#.......##.#..#..#.....#.......#.###.#
...........###..#####.#..##.......#.#........#.#.....#.......#......#....#..#..#.............
#...#.#........

output:

-1

result:

ok single line: '-1'

Test #37:

score: 0
Accepted
time: 6ms
memory: 4984kb

input:

96 97
#............#.................#....#.#.#...#....#..###..#.#....#.##...#..#...........#..........
..#.........##........#...#.##....##....###...#.###..#.#..............##.#.....................#.
..#..........#.#.#..#...........#...##............#......##...................#......##....#.....
...

output:

-1

result:

ok single line: '-1'

Test #38:

score: 0
Accepted
time: 8ms
memory: 5236kb

input:

91 94
#...........#.#.##.#..#.....#.#........S.##.......##....#..#........#..#...#..#..#........#U#.
...#.....#..#.....##.#..#.##....#...#.##....#....#......##.#.#............##.......#....#....#
#..#...#..#...#.#..###.#...#....#..##....#....##....#.#.##.........#..#...#.#........#.#.#..##
....##......

output:

4

result:

ok single line: '4'

Test #39:

score: 0
Accepted
time: 4ms
memory: 5048kb

input:

94 91
...........#......#...#.....#..###.....#.......#....##.#....#........#......####.......#...
..#...###...##.......#..#....#..#.###.#....#......#.#..####.##...#...#..##..#.#...###..#...
..#.#.##..#...........#.........#.#.......#...........#.###......#..#....#......#...#......
.#.....##..#.....#...

output:

21

result:

ok single line: '21'

Test #40:

score: 0
Accepted
time: 1ms
memory: 5096kb

input:

90 94
##..........#.#.#.....#.....#..#..#......#.#..##..##....##..#.#.#..#.###.#...#.........T.#....
....#.#.....#.#...............##..#..##.##.#..#....##....###.#.#.#...#..###.........#.##....##
...##.............#..#.....#..#..#.......#....#...###....#.#..#...#.#....#...###..####........
#..##...#...

output:

24

result:

ok single line: '24'

Test #41:

score: 0
Accepted
time: 2ms
memory: 4616kb

input:

93 98
.............#.........#.....U..#......................##.........................................
...........#............#...........................................................###...#.......
....................................................................................#..............

output:

-1

result:

ok single line: '-1'

Test #42:

score: 0
Accepted
time: 6ms
memory: 5100kb

input:

96 100
..........#........#..#...#..#.........#....#....#.#.....##......##....##............#.............#
.......#.#..#.#.#..#....................#..............##.....#.........#...#...#.....#.....#.....#.
##.....##.#.###...#...#.#.............###.#.......#.#................#........#........##.....

output:

12

result:

ok single line: '12'

Test #43:

score: 0
Accepted
time: 4ms
memory: 5028kb

input:

100 99
................#..#............T.....#.....#.....#............#.#.....U.#..#.....#..........#.....
.................................#.#...............................................................
............#..........#..#..#.........#...................#............................#.......

output:

100

result:

ok single line: '100'

Test #44:

score: 0
Accepted
time: 2ms
memory: 4084kb

input:

13 22
..#...#U#......#....##
......##.............#
......#....#...#.....#
.........#..#.........
...................#..
......###.........#..#
....#..............#.T
.#..#...#.............
#.....#.....##...#....
.#.........#.##.......
......#..#............
.#.....#...#...#......
..S..#.#.............

output:

0

result:

ok single line: '0'

Test #45:

score: 0
Accepted
time: 2ms
memory: 4332kb

input:

84 35
...#.#.#.......###..#......##.###..
...#....##.#..##......###.#..#.##..
...###.....#..###.#..#.#..#...#...#
#...###.#..#..#....#...#.#.#.....#.
###...##......#.##.#.....#...#.#..#
...#.#...###......#.....#....#....#
#.#..##.##.###...#..###....##.##...
###..#.#........#...#.#.##.#.#.....
...#.....

output:

0

result:

ok single line: '0'

Test #46:

score: 0
Accepted
time: 1ms
memory: 4148kb

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: 6ms
memory: 4708kb

input:

85 67
...##....##..#..#....##..##S.##...#....#.#............#............
.......#.#..#....#..#..#.#...##..##.#...#.#.#...#......#.....##..#.
..#.....#.....#.#.......#.....#.......#..#.###..#.........#........
##.#.#.#.#.###.#..........##....#.....#.#..##.#...........#...###.#
...........#.......#.....

output:

0

result:

ok single line: '0'

Test #48:

score: 0
Accepted
time: 2ms
memory: 4332kb

input:

42 30
##.....##.#.#T.#.#.#.#....#.#.
..#.......##...#.#.#...#......
#.........#...#.##....#..#....
.....#..#....#..#...##...####.
#.......###...#..#......#..#..
...#.....#......#..#......#.##
##.#.#.#..#...#.......####....
....#...##.....#....#.#.#.....
........#..#.#......#....#.#..
.#.##.#...###.....

output:

0

result:

ok single line: '0'

Test #49:

score: 0
Accepted
time: 3ms
memory: 4548kb

input:

62 62
..........##...#.#.............#.#..........#.................
...............#.#............#..........................#....
...................#.........................##...............
........#............#..................#................#....
..........................#..#.......##......

output:

8

result:

ok single line: '8'

Test #50:

score: 0
Accepted
time: 0ms
memory: 4996kb

input:

89 74
...#....#.#....#...........#..#T.#....................##.U.............##.
...##.....#......##......................#....#.#..#....#..#........##....
...#.##............#...#.........#........#.#..........##.#..#............
.#.......#.....#.....#..#..............##.#................#............

output:

4

result:

ok single line: '4'

Test #51:

score: 0
Accepted
time: 2ms
memory: 4472kb

input:

100 37
.....................#..#.........#..
.............#........#........#.....
...........#.........................
..##..#.....#.............#..........
............#..................#.....
#..#................##...#...........
..#...........#...#..................
..................#.#.....#...

output:

6

result:

ok single line: '6'

Test #52:

score: 0
Accepted
time: 5ms
memory: 4520kb

input:

44 89
...#.#.#...##.#.#.....#..##..#.#......##.........#..##....#.....##....##.#.........#..#..
##....##.#...........#...#..##.#....#...#.#.#......#........#..#..........#.......##....#
....#..#...#.#......#.#...###.#......#....#.#.#......#...##..............##.#.##...#..#..
.#.....###.#..#...#..#.....

output:

4

result:

ok single line: '4'

Test #53:

score: 0
Accepted
time: 3ms
memory: 4404kb

input:

68 17
##.....#....#....
.#.##...#...#...#
...#....#....##..
..#...#........#.
..#..####.#...##.
.....###.........
.#.........#..#.#
....#.#.#.#.....#
...#.....#.......
#..#.###...####..
..##.##....#.#...
##.....#.#.....#.
....#....#......#
..##.............
.....#.........#.
....#...........#
..##.....

output:

6

result:

ok single line: '6'

Test #54:

score: 0
Accepted
time: 1ms
memory: 4076kb

input:

16 23
..#..##.#U.#...#....#.#
...#...##.##.#...##...#
...#.#..#..##.#..#.#...
...#..#.#.#..#....#...#
##..#..#........#......
.......#.#.#........#..
.#.....#...#..#.#......
........#..###.....###.
.##.......#.###..##.#..
.....#..######......#..
#..#....#....#.#....#.#
....#.#..#....##....##.
.#.#.....

output:

-1

result:

ok single line: '-1'

Test #55:

score: 0
Accepted
time: 2ms
memory: 4132kb

input:

43 67
.............#....#.............................S.#............#...
..........#.................#.............#........................
................................#................................#.
.........................#..........#...........#..................
....#....................

output:

-1

result:

ok single line: '-1'

Test #56:

score: 0
Accepted
time: 3ms
memory: 4336kb

input:

79 22
.#......#..#...#.#...#
............#.........
.###.......#.#..#....#
..#..#...........##...
......#.....###....#.#
#.......#..#........#.
.....#.....#..........
......#.#.#.......#...
....#......##..#....#.
...#...#......##......
.....#...#.#..###.....
.....###.......#......
#...........#..#.....

output:

-1

result:

ok single line: '-1'

Test #57:

score: 0
Accepted
time: 2ms
memory: 4136kb

input:

9 18
...#...#....#....#
.........##.......
..#.....#.#..###.U
...#..#..####...#T
.#.###.##.......#.
......#....####.#.
#....#....##.#..##
S............#.#..
###..#....#...#..#
0

output:

-1

result:

ok single line: '-1'

Test #58:

score: 0
Accepted
time: 1ms
memory: 4324kb

input:

40 72
#...#...#......#.#.#....#.##..##.#..##.#####..#.##...###.#.####..##.....
.###.#..#.......#..#..#..#.#.#....##.....#..###.#..#.##..#.#.#....#....#
..#.#..#..#..#....#..####....#.#....##............#..#...##..#.#.#..#..#
####..#.##.....#..#........#.#......#...#..###.......##..#..............
.....

output:

-1

result:

ok single line: '-1'

Test #59:

score: 0
Accepted
time: 3ms
memory: 4996kb

input:

100 100
....................................................................................................
.........#..........................................................................................
.........................................................................................#...

output:

-1

result:

ok single line: '-1'

Test #60:

score: 0
Accepted
time: 4ms
memory: 4516kb

input:

100 100
...........#..........................##...#....#.#..............##.....#.#..........#.......#...#..
.....#.....#...#...........#....##............#.....##................#..##.......###...#...........
..#......##.....#.#.#.....#...#.#.....#..#........................#.#.#........#.#..###..#...

output:

-1

result:

ok single line: '-1'

Test #61:

score: 0
Accepted
time: 0ms
memory: 5140kb

input:

100 100
................##.....#........................................#...##.......#...#..S...##.......U..
...#.....#..................................#.............###......................#................
.........#....#......#.....................................#......#.............#............

output:

-1

result:

ok single line: '-1'

Test #62:

score: 0
Accepted
time: 9ms
memory: 5024kb

input:

100 100
..........................#........#..............#.........##.#.#....#....#...#....................
.......................#.................#..##..................#.....................#..#.#........
...........#....................#....................#....#...................#..............

output:

17

result:

ok single line: '17'

Test #63:

score: 0
Accepted
time: 3ms
memory: 5028kb

input:

100 100
.......................................U............................................................
............................................................................##......................
.............................................................#...............................

output:

42

result:

ok single line: '42'

Test #64:

score: 0
Accepted
time: 11ms
memory: 6108kb

input:

100 100
....................................................................................................
....................................................................................................
.............................................................................................

output:

10

result:

ok single line: '10'

Test #65:

score: 0
Accepted
time: 3ms
memory: 6200kb

input:

100 100
#........................................#.......................#..................................
..............................................#......#..................#......................#....
....#...........#................#......#....................................................

output:

10

result:

ok single line: '10'

Test #66:

score: 0
Accepted
time: 8ms
memory: 6104kb

input:

100 100
...##.##......##.........#....###...#.#..#.#..##..###..#..#.#..#...#.#.........#.#.#....#.#..#.#...T
...#.#..##.#..#.#.................#..............#.#.....#........##....#....#..........#..#.#......
#.#.....#...#...#..##...................#.#..#..##.#......#..#........#.#....#...#...#.......

output:

3

result:

ok single line: '3'

Test #67:

score: 0
Accepted
time: 11ms
memory: 6184kb

input:

100 100
.............................#.......................#..............................................
...............................................................................#....................
......#...###.......................................................##............#..........

output:

6

result:

ok single line: '6'

Test #68:

score: 0
Accepted
time: 12ms
memory: 6124kb

input:

100 100
.......#......................#.....#.............#.....T.......#.............#.....................
.....................................#..............................#...................#.......##..
................................#....#........................#..............................

output:

7

result:

ok single line: '7'

Test #69:

score: 0
Accepted
time: 0ms
memory: 4992kb

input:

100 100
S..................................................................................................T
....................................................................................................
.............................................................................................

output:

9902

result:

ok single line: '9902'

Test #70:

score: 0
Accepted
time: 7ms
memory: 4952kb

input:

100 100
S..................................................................................................T
....................................................................................................
.............................................................................................

output:

9506

result:

ok single line: '9506'

Test #71:

score: 0
Accepted
time: 4ms
memory: 5024kb

input:

100 100
S..................................................................................................T
....................................................................................................
.............................................................................................

output:

2280

result:

ok single line: '2280'

Test #72:

score: 0
Accepted
time: 5ms
memory: 5100kb

input:

100 100
S..................................................................................................T
....................................................................................................
.............................................................................................

output:

1470

result:

ok single line: '1470'

Test #73:

score: 0
Accepted
time: 8ms
memory: 4940kb

input:

100 100
S..................................................................................................T
....................................................................................................
.............................................................................................

output:

102

result:

ok single line: '102'

Test #74:

score: 0
Accepted
time: 1ms
memory: 4112kb

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: 3996kb

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: 4012kb

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: 1ms
memory: 4020kb

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: 4160kb

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'