CSES - Aalto Competitive Programming 2024 - wk2 - Mon - Results
Submission details
Task:Abandoned warehouse
Sender:joaquimballester
Submission time:2024-09-09 17:48:43 +0300
Language:C++11
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#60.06 sdetails
#7--details
#8--details
#9--details
#10--details
#110.00 sdetails
#120.00 sdetails
#13--details
#140.00 sdetails
#150.00 sdetails
#16--details

Compiler report

input/code.cpp: In function 'bool dl(Mapa&, int, int)':
input/code.cpp:13:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |         return not (x < 0 or x >= m.size() or y < 0 or y >= m[0].size() );
      |                              ~~^~~~~~~~~~~
input/code.cpp:13:58: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |         return not (x < 0 or x >= m.size() or y < 0 or y >= m[0].size() );
      |                                                        ~~^~~~~~~~~~~~~~
input/code.cpp: In function 'int found(Mapa&, int, int)':
input/code.cpp:17:13: warning: unused variable 'rows' [-Wunused-variable]
   17 |         int rows        = m.size();
      |             ^~~~
input/code.cpp:18:13: warning: unused variable 'columns' [-Wunused-variable]
   18 |...

Code

#include <iostream>
#include <vector>
#include <queue>
#include <string>
using namespace std;
typedef vector< vector<char> > Mapa;
typedef pair<int,int> par;
typedef pair<par,int> Coord;

#define inf 0x7fffffff

bool dl(Mapa& m,int x, int y){
	return not (x < 0 or x >= m.size() or y < 0 or y >= m[0].size() );
}

int found(Mapa& m,int x,int y){
	int rows 	= m.size();
	int columns	= m[0].size();	
	queue<Coord> Q;
    queue<string> Camins;
    Camins.push("");
	Q.push( Coord(par(x,y),0) );
    pair<int, string> ret;
    ret.first = inf;
    ret.second = "";
	while( not Q.empty() ){
		Coord v = Q.front();
        string cami = Camins.front();
        Camins.pop();
		Q.pop();
		if(v.second > ret.first) break;
		if(m[v.first.first][v.first.second] == 'B') if(v.second<ret.first) {
            ret.first = v.second;
            ret.second = cami;
        }
		m[v.first.first][v.first.second]='#';
		int esq = v.first.first-1;
		int dre = v.first.first+1;
		int ada = v.first.second-1;
		int aba = v.first.second+1;

		if(dl(m,esq,v.first.second) ) if(m[esq][v.first.second]!='#'){
            Q.push( Coord( par(esq,v.first.second), v.second+1 ) );
            Camins.push(cami+"L");
        }
		if(dl(m,dre,v.first.second) ) if(m[dre][v.first.second]!='#'){
            Q.push( Coord( par(dre,v.first.second), v.second+1 ) );
            Camins.push(cami+"R");


        }
		if(dl(m,v.first.first,ada) )  if(m[v.first.first][ada]!='#'){
            Q.push( Coord( par(v.first.first,ada), v.second+1 ) );
            Camins.push(cami+"U");

        }
		if(dl(m,v.first.first,aba) )  if(m[v.first.first][aba]!='#'){
            Q.push( Coord( par(v.first.first,aba), v.second+1 ) );
            Camins.push(cami+"D");
        }

	}
	return ret.first;
}

int main(){

	int n,m;
    int f,c;
	cin >> n >> m;
	Mapa mapt(n, vector<char>(m) );
	for(int i = 0; i < n ; ++i)
		for(int j = 0; j < m; ++j){
			cin >> mapt[i][j];
            if(mapt[i][j] == 'A'){
                f = i;
                c = j;
            }
        }
        
	int dmin = found(mapt,f,c);
	if( dmin != inf )
		cout << "distancia minima: " << dmin << endl;
	else
		cout << "no es pot arribar a cap tresor" << endl;
}

Test details

Test 1

Verdict:

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

correct output
NO

user output
no es pot arribar a cap tresor

Test 2

Verdict:

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

correct output
NO

user output
no es pot arribar a cap tresor

Test 3

Verdict:

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

correct output
YES
3
LLD

user output
distancia minima: 3

Test 4

Verdict:

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

correct output
YES
1
R

user output
distancia minima: 1

Test 5

Verdict:

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

correct output
YES
3
RDD

user output
distancia minima: 3

Test 6

Verdict:

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

correct output
NO

user output
no es pot arribar a cap tresor

Test 7

Verdict:

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

correct output
YES
626
LLLDDRDDDDLDLDDLLLLLDDDDLLDLDL...

user output
(empty)

Test 8

Verdict:

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

correct output
YES
364
LULULLULLLULLLLLUULLLLUUULLLLL...

user output
(empty)

Test 9

Verdict:

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

correct output
YES
1003
LLLLLLLLLLLLLLLLLLLLLLLLLDLLLL...

user output
(empty)

Test 10

Verdict:

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

correct output
YES
947
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL...

user output
(empty)

Test 11

Verdict:

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

correct output
YES
2000
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...

user output
distancia minima: 2000

Test 12

Verdict:

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

correct output
YES
2000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
distancia minima: 2000

Test 13

Verdict:

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

correct output
YES
499998
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...

user output
(empty)

Test 14

Verdict:

input
1 3
A.B

correct output
YES
2
RR

user output
distancia minima: 2

Test 15

Verdict:

input
2 2
##
AB

correct output
YES
1
R

user output
distancia minima: 1

Test 16

Verdict:

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

correct output
YES
1998
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)