Submission details
Task:Robotti
Sender:Lelleri
Submission time:2026-01-17 13:23:51 +0200
Language:C++ (C++11)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.01 sdetails

Code

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define FAST ios::sync_with_stdio(0); cin.tie(0);

int n;
vector<vector<char>> grid;


int next_step(int y, int x, pii dir, int steps){
    pii new_dir = dir;

    if(grid[y][x] == '/'){
        if(dir.first == -1) new_dir = {0, 1};
        else if(dir.first == 1) new_dir = {0, -1};
        else if(dir.second == 1) new_dir = {-1, 0};
        else if(dir.second == -1) new_dir = {1, 0};
        grid[y][x] = '\\';
    }
    else if(grid[y][x] == '\\'){
        if(dir.first == -1) new_dir = {0, -1};
        else if(dir.first == 1) new_dir = {0, 1};
        else if(dir.second == 1) new_dir = {1, 0};
        else if(dir.second == -1) new_dir = {-1, 0};
        grid[y][x] = '/';
    }

    int new_y_loc = y+new_dir.first;
    int new_x_loc = x+new_dir.second;

    if(new_y_loc < 0 || new_y_loc >= n) return steps +1;
    if(new_x_loc < 0 || new_x_loc >= n) return steps +1;

    steps = next_step(new_y_loc, new_x_loc, new_dir, steps+1);

    return steps;
}

int main(){
    
    cin >> n;

    grid.assign(n, vector<char>(n));

    for(int i=0; i<n; i++){
        for (int j = 0; j < n; j++)
        {
            cin >> grid[i][j];
        }   
    }

    int ans = next_step(0, 0, {1, 0}, 0);
    cout << ans;

    return 0;
}

Test details

Test 1 (public)

Verdict: ACCEPTED

input
3
./\
\./
\/.

correct output
13

user output
13

Test 2

Verdict: ACCEPTED

input
1
.

correct output
1

user output
1

Test 3

Verdict: ACCEPTED

input
5
./\/\
.....
.....
.....
...

correct output
25

user output
25

Test 4

Verdict: ACCEPTED

input
5
\\/\\
/\/\/
\\/\\
/\/\/
...

correct output
37

user output
37

Test 5

Verdict: ACCEPTED

input
20
\\/\/\/\\./\\.\/\/\.
/\\\\\\/\\\\\\\\\\\.
\\\\\\\\\\\\\\\\\\\\
/\\\\\\\\\\\\\.\\\\\
...

correct output
2519

user output
2519

Test 6

Verdict: ACCEPTED

input
20
\\..................
.\\..............\\.
..\\............\\..
...\\..........\\...
...

correct output
917489

user output
917489