CSES - Aalto Competitive Programming 2024 - wk2 - Mon - Results
Submission details
Task:Abandoned warehouse
Sender:auni
Submission time:2024-09-09 17:04:28 +0300
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#40.00 sdetails
#50.00 sdetails
#6ACCEPTED0.06 sdetails
#70.19 sdetails
#80.21 sdetails
#90.23 sdetails
#100.19 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.18 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#160.30 sdetails

Code

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define REP(i,a,b) for (int i = a; i < b; i++)

bool visit(int v, vector<bool> &visited, const vector<vector<int>> &edges, int goal, stack<char> &path) {
    if(visited[v]) return false;
    if(v == goal) {
        return true;
    }
    visited[v] = true;
    for(auto e: edges[v]) {
        bool f = visit(e, visited, edges, goal, path);
        if(f) {
            
            if(e-v == 1) {
                path.push('R');
            } else if(e-v == -1) {
                path.push('L');
            } else if(e-v > 0) {
                path.push('D');
            } else {
                path.push('U');
            }
            return true;
        }
    }
    return false;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    // vector<int> nodes(n);
    vector<int> map(n*m);
    vector<vector<int>> edges(n*m);
    int start= 0;
    int goal = 0;

    REP(i, 0, n) {
        REP(j, 0, m) {
            char a;
            cin >> a;

            if(a == 'A') {
                start = i*m+j;
                map[i*m + j] = '.';
                if(i > 0 && map[(i-1)*m + j] == '.') {
                    edges[(i-1)*m + j].PB((i)*m + j);
                    edges[(i)*m + j].PB((i-1)*m + j);
                } 
                if(j > 0 && map[(i)*m + j - 1] == '.') {
                    edges[(i)*m + j-1].PB((i)*m + j);
                    edges[(i)*m + j].PB((i)*m + j-1);
                }
            } else if(a == 'B') {
                goal = i*m+j;
                map[i*m + j] = '.';
                if(i > 0 && map[(i-1)*m + j] == '.') {
                    edges[(i-1)*m + j].PB((i)*m + j);
                    edges[(i)*m + j].PB((i-1)*m + j);
                } 
                if(j > 0 && map[(i)*m + j - 1] == '.') {
                    edges[(i)*m + j-1].PB((i)*m + j);
                    edges[(i)*m + j].PB((i)*m + j-1);
                }
            } else if(a == '.') {
                map[i*m + j] = '.';
                if(i > 0 && map[(i-1)*m + j] == '.') {
                    edges[(i-1)*m + j].PB((i)*m + j);
                    edges[(i)*m + j].PB((i-1)*m + j);
                } 
                if(j > 0 && map[(i)*m + j - 1] == '.') {
                    edges[(i)*m + j-1].PB((i)*m + j);
                    edges[(i)*m + j].PB((i)*m + j-1);
                }
            } else {
                map[i*m + j] = '#';
            }
        }
    }

    vector<bool> visited(n*m);
    stack<char> path;

    bool found = visit(start, visited, edges, goal, path);
    if(found) {
        cout << "YES" << "\n";
        cout << (int)path.size() << "\n";
        while(!path.empty()) {
            cout << path.top();
            path.pop();
        }
        cout << "\n";
    } else {
        cout << "NO" << "\n";
    }

    return 0;
}


Test details

Test 1

Verdict: ACCEPTED

input
10 10
##.A######
#.##.##.##
#####..###
.#########
...

correct output
NO

user output
NO

Test 2

Verdict: ACCEPTED

input
10 10
B#..##.#..
#....A##..
#.....#..#
.#......#.
...

correct output
NO

user output
NO

Test 3

Verdict: ACCEPTED

input
10 10
...#..A.#.
....B...##
...#......
..........
...

correct output
YES
3
LLD

user output
YES
3
LLD

Test 4

Verdict:

input
10 10
.#........
..........
..........
........#.
...

correct output
YES
1
R

user output
YES
73
UUUUUUUULLLLLDLLDRRRURRRDLLDLL...

Test 5

Verdict:

input
10 10
..........
..........
..........
..........
...

correct output
YES
3
RDD

user output
YES
79
UUUUULLLDRRDLLDRRDLLDRRDLLDRRR...

Test 6

Verdict: ACCEPTED

input
1000 1000
##.###..######.#########.###.#...

correct output
NO

user output
NO

Test 7

Verdict:

input
1000 1000
####.#.###....#.......##.##.#....

correct output
YES
626
LLLDDRDDDDLDLDDLLLLLDDDDLLDLDL...

user output
YES
248118
UUUUUUUUUUUUUUUUUUULUUUUUUULLU...
Truncated

Test 8

Verdict:

input
1000 1000
....#.##......#....#......#......

correct output
YES
364
LULULLULLLULLLLLUULLLLUUULLLLL...

user output
YES
324322
UUUUUULUUUUUUUUUUULLLUUUUURUUR...
Truncated

Test 9

Verdict:

input
1000 1000
.................#......#........

correct output
YES
1003
LLLLLLLLLLLLLLLLLLLLLLLLLDLLLL...

user output
YES
420235
LLULLLLUUUUUUUUUUUUUUUURUUUUUU...
Truncated

Test 10

Verdict:

input
1000 1000
.................................

correct output
YES
947
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL...

user output
YES
84935
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUU...
Truncated

Test 11

Verdict: ACCEPTED

input
1000 3
A#B
.#.
.#.
.#.
...

correct output
YES
2000
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...

user output
YES
2000
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...
Truncated

Test 12

Verdict: ACCEPTED

input
3 1000
A................................

correct output
YES
2000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
YES
2000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
Truncated

Test 13

Verdict: ACCEPTED

input
999 999
A#...#...#...#...#...#...#...#...

correct output
YES
499998
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...

user output
YES
499998
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...
Truncated

Test 14

Verdict: ACCEPTED

input
1 3
A.B

correct output
YES
2
RR

user output
YES
2
RR

Test 15

Verdict: ACCEPTED

input
2 2
##
AB

correct output
YES
1
R

user output
YES
1
R

Test 16

Verdict:

input
1000 1000
A................................

correct output
YES
1998
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
YES
999000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
Truncated