p484.ans1
======================
2

=================
p484.ans2
======================
-1

=================
p484.ans3
======================
-1

=================
p484.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n, m;
vector<string> grid;

void read() {
    cin >> n >> m;
    grid.resize(n);
    cin >> grid;
}

void solve() {
    // Simulate the bottle row by row. Find P, then for each row below track
    // the current column pos. A '\' deflects right (pos+1) and a '/' deflects
    // left (pos-1); if the deflection lands on an obstacle of the opposite
    // type the bottle stops (type change), encoded as pos = -1. Going off
    // either side (wall) also stops the bottle, encoded by setting pos = -2
    // and breaking. If the bottle falls past the last row pos still holds the
    // exit column; we print pos + 1, which becomes -1 when the bottle stopped.

    int x = 0, y = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(grid[i][j] == 'P') {
                x = i;
                y = j;
            }
        }
    }

    int pos = y;
    int i = x + 1;
    while(i < n) {
        if(grid[i][pos] == '\\') {
            pos += 1;
            if(pos < m && grid[i][pos] == '/') {
                pos = -1;
            }
        } else if(grid[i][pos] == '/') {
            pos -= 1;
            if(pos >= 0 && grid[i][pos] == '\\') {
                pos = -1;
            }
        }

        if(pos < 0 || pos >= m) {
            pos = -2;
            break;
        }

        i += 1;
    }

    cout << pos + 1 << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}

=================
p484.in1
======================
2 3
./P
../

=================
p484.in2
======================
2 2
.P
\/

=================
p484.in3
======================
5 4
.P..
.\..
.//.
./..
/...

=================
p484.py
======================
n, m = map(int, input().split())
grid = [list(input()) for _ in range(n)]
for i in range(n):
    for j in range(m):
        if grid[i][j] == 'P':
            x, y = i, j
pos = y
i = x + 1
while i < n:
    if grid[i][pos] == '\\':
        pos += 1
        if pos < m and grid[i][pos] == '/':
            pos = -1
    elif grid[i][pos] == '/':
        pos -= 1
        if pos >= 0 and grid[i][pos] == '\\':
            pos = -1
    if pos < 0 or pos >= m:
        pos = -2
        break
    i += 1
print(pos + 1)

=================
statement.txt
======================
484. Kola
Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



One day Vasya decided to buy a bottle of his favourite Kola in the old vending machine. But he forgot that there was a Halloween that day, so evil forces had made an inner structure of the vending machine quite complicated. Inside the machine is represented by a table of size n × m. Some of the cells are empty, and some contains obstacles of two types: '/' and '\'. One of the cell initially contains a bottle of Kola. After the purchasing it starts to fall vertically down by the following rules:
If a cell immediately below the bottle is empty, the bottle falls down.
If the bottle falls down from the lowest row, it falls to the tray and Vasya can take it.
Reaching and obstacle '/' ('\') the bottle moves left (right) without changing it's row and tries to continue to fall down if it is possible.
The bottle stops to move when there is a wall in the current moving direction.
The bottle stops to move when it moves from the cell with an obstacle of one type to the cell with an obstacle of another type.
But if the bottle moves to the cell with the same type of obstacle as in the current cell, it continues moving down.


Help Vasya to find out whether the bottle will reach the tray. In case of a positive answer, determine the number of column where it will happen.

Input
The first line of the input contains two integer numbers n and m (1 ≤ n, m ≤ 100). Then the description of the vending machine follows. It consists of n lines of m characters each: '.' means empty cell, 'P' means initial position of the bottle, '/' and '\' — mean obstacles of the corresponding type. It is guaranteed that the 'P' character appears exactly once.

Output
Print to the output -1 if the bottle doesn't reach the tray. Otherwise print the number of the column where the bottle will leave the vending machine. Columns are numbered starting from 1 from the leftmost one.

Example(s)
sample input
sample output
2 3
./P
../
2

sample input
sample output
2 2
.P
\/
-1

sample input
sample output
5 4
.P..
.\..
.//.
./..
/...

=================
