| Task: | Robotti |
| Sender: | sandyy |
| Submission time: | 2026-01-17 13:21:30 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 100 |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.00 s | details |
| #3 | ACCEPTED | 0.00 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | ACCEPTED | 0.00 s | details |
| #6 | ACCEPTED | 0.01 s | details |
Compiler report
input/code.cpp: In function 'void dfs(int, int, int)':
input/code.cpp:12:6: warning: infinite recursion detected [-Winfinite-recursion]
12 | void dfs(int x, int y, int d) {
| ^~~
input/code.cpp:44:12: note: recursive call
44 | dfs(x+dx[nd], y+dy[nd], nd);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:44:20: warning: 'nd' may be used uninitialized [-Wmaybe-uninitialized]
44 | dfs(x+dx[nd], y+dy[nd], nd);
| ~~~~~^
input/code.cpp:18:13: note: 'nd' was declared here
18 | int nd;
| ^~Code
#include<bits/stdc++.h>
using namespace std;
const int mxN=20;
int n, ans=0;
char grid[mxN][mxN];
// D R U L
int dx[4]{1, 0, -1, 0};
int dy[4]{0, 1, 0, -1};
void dfs(int x, int y, int d) {
if(x<0 || x==n || y<0 || y==n) {
cout << ans;
exit(0);
}
ans++;
int nd;
if(grid[x][y]=='/') { // depending on the direction
grid[x][y]='\\';
if(d==1) { // we were going right, now we are going up
nd=2;
} else if(d==0) { // we are going down
nd=3;
} else if(d==2) { // we were going up
nd=1;
} else if(d==3) { // we were going to the left
nd=0;
}
} else if(grid[x][y]=='\\') { // depending on the direction
grid[x][y]='/';
if(d==0) {
nd=1;
} else if(d==1) {
nd=0;
} else if(d==2) {
nd=3;
} else if(d==3) {
nd=2;
}
} else { // do the same thing
nd=d;
}
dfs(x+dx[nd], y+dy[nd], nd);
return;
}
int main() {
cin >> n;
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
cin >> grid[i][j];
}
}
dfs(0, 0, 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 |
