CSES - Datatähti 2025 loppu - Results
Submission details
Task:Suunnistus
Sender:Touko_Ursin
Submission time:2025-01-18 15:52:16 +0200
Language:C++ (C++20)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.00 s3details
#20.00 s1, 2, 3details
#30.01 s1, 2, 3details
#40.00 s1, 2, 3details
#50.00 s1, 2, 3details
#60.00 s1, 2, 3details
#70.00 s2, 3details
#80.00 s2, 3details
#90.00 s2, 3details
#100.00 s3details
#110.00 s3details
#120.00 s3details
#130.00 s3details
#140.00 s2, 3details
#150.00 s3details
#160.00 s3details
#170.00 s2, 3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

Code

#include <bits/stdc++.h>

using namespace std;

int counts = 0;
int rasti = 1;
int n, m, k;
vector<int> tripdist;
vector<vector<int>> kartta;
vector<vector<int>> visited;
pair<int,int> alku;
pair<int,int> loppu;
queue<pair<pair<int,int>, int>> cords;
bool found = false;

int main(){
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    
    cin>>n>>m>>k;



    kartta.resize(n);
    visited.resize(n);
    for(int i = 0; i<n; i++){
        kartta[i].resize(m, 0);
    }
    for(int i = 0; i<n; i++){
        visited[i].resize(m, 0);
    }

    string x;

    for(int i = 0; i<n; i++){
        cin>>x;

        for(int j = 0; j<m; j++){
            if(x[j] == '#'){
                kartta[i][j] = -1;
            }
            else if(x[j] == '.') kartta[i][j] = 11;
            else if(x[j]=='S'){
                kartta[i][j] = 0;
                alku = {i,j};
            } 
            else if(x[j]=='E'){
                loppu = {i,j};
                kartta[i][j] = k+1;
            } 
            else{
                kartta[i][j] = x[j] - '0';
            }
            

        }
    }

    cords.push({{alku.first, alku.second}, 0});
    while(rasti != k+2 && !cords.empty()){
        int x = cords.front().first.first;
        int y = cords.front().first.second;
        int steps = cords.front().second;


        if(steps>n*m){
            cout<<"-1"<<endl;
            return 0;
        } 
        cords.pop();
        if(x != 0 && kartta[x-1][y] != -1 && !visited[x-1][y]){
            if(kartta[x-1][y] == rasti){
                rasti++;
                queue<pair<pair<int,int>, int>> chords;
                cords = chords;
                cords.push({{x, y}, steps+1});
                break;
                
            } 
            visited[x-1][y] = 1;
            cords.push({{x-1, y},steps+1});
        }
        if(x != n-1&& kartta[x+1][y] != -1&& !visited[x+1][y]){
            if(kartta[x+1][y] == rasti){
                rasti++;
                queue<pair<pair<int,int>, int>> chords;
                cords = chords;
                cords.push({{x, y}, steps+1});
                break;
            } 
            visited[x+1][y] = 1;
            cords.push({{x+1, y},steps+1});
        }
        if(y != 0&& kartta[x][y-1] != -1 && !visited[x][y-1]){
            if(kartta[x][y-1] == rasti){
                rasti++;
                queue<pair<pair<int,int>, int>> chords;
                cords = chords;
                cords.push({{x, y}, steps+1});
                break;
            }
            visited[x][y-1] = 1;
            cords.push({{x, y-1}, steps+1});
        }
        if(y != m-1 && kartta[x][y+1] != -1 && !visited[x][y+1]){
            if(kartta[x][y+1] == rasti){
                rasti++;
                queue<pair<pair<int,int>, int>> chords;
                cords = chords;
                cords.push({{x, y}, steps+1});
                break;
            } 
            visited[x][y+1] = 1;
            cords.push({{x, y+1}, steps+1});
        }   

    }

    if(cords.empty()){
        cout<<"-1";
        return 0;
    }
    cout<<cords.front().second+k;

}

Test details

Test 1

Group: 3

Verdict:

input
10 10 9
S293#35616
#662963731
54975451#7
5162589168
...

correct output
25

user output
(empty)

Test 2

Group: 1, 2, 3

Verdict:

input
500 500 0
.................................

correct output
301

user output
(empty)

Test 3

Group: 1, 2, 3

Verdict:

input
500 500 0
.#.........#.#..##..#............

correct output
253

user output
(empty)

Test 4

Group: 1, 2, 3

Verdict:

input
500 500 0
...#......##.##.#.#..##..#..##...

correct output
-1

user output
(empty)

Test 5

Group: 1, 2, 3

Verdict:

input
500 1 0
.
.
.
.
...

correct output
77

user output
(empty)

Test 6

Group: 1, 2, 3

Verdict:

input
1 500 0
.................................

correct output
166

user output
(empty)

Test 7

Group: 2, 3

Verdict:

input
500 500 9
.................................

correct output
3447

user output
(empty)

Test 8

Group: 2, 3

Verdict:

input
500 500 9
.#........#..................#...

correct output
4952

user output
(empty)

Test 9

Group: 2, 3

Verdict:

input
500 500 9
##.########.##########.#..#......

correct output
-1

user output
(empty)

Test 10

Group: 3

Verdict:

input
500 500 9
623475428948841896621266296765...

correct output
205

user output
(empty)

Test 11

Group: 3

Verdict:

input
500 500 9
7##814125813#3463#272134469457...

correct output
157

user output
(empty)

Test 12

Group: 3

Verdict:

input
500 500 9
##67##36##5#3###67###8972#61##...

correct output
-1

user output
(empty)

Test 13

Group: 3

Verdict:

input
500 500 9
....................#...#........

correct output
1313

user output
(empty)

Test 14

Group: 2, 3

Verdict:

input
499 499 9
S#...#...#...#...#...#...#...#...

correct output
1124942

user output
(empty)

Test 15

Group: 3

Verdict:

input
500 1 9
1
6
1
3
...

correct output
332

user output
(empty)

Test 16

Group: 3

Verdict:

input
1 500 9
996327784392827829434482995353...

correct output
135

user output
(empty)

Test 17

Group: 2, 3

Verdict:

input
500 500 9
.................................

correct output
-1

user output
(empty)