답안 #625187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625187 2022-08-09T14:47:50 Z Stavab Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1173 ms 636720 KB
#include <iostream>
#include <vector>
#include <utility>
#include <queue>

using namespace std;

vector<vector<char>> field;
vector<vector<int>> turn;
int h, w, answer = 1;
queue<pair<int, int>> points;

void scan(pair<int, int> p)
{
    int i = p.first;
    int j = p.second;
    
    if(i != 0)
    {
        if(!turn[i - 1][j] && field[i - 1][j] != '.')
        {
            if(field[i - 1][j] == field[i][j])
            {
                turn[i - 1][j] = turn[i][j];
                scan({i - 1, j});
            }
            else
            {
                turn[i - 1][j] = turn[i][j] + 1;
                points.push({i - 1, j});
            }
        }
    }
    if(j != 0)
    {
        if(!turn[i][j - 1] && field[i][j - 1] != '.')
        {
            if(field[i][j - 1] == field[i][j])
            {
                turn[i][j - 1] = turn[i][j];
                scan({i, j - 1});
            }
            else
            {
                turn[i][j - 1] = turn[i][j] + 1;
                points.push({i, j - 1});
            }
        }
    }
    if(i != h - 1)
    {
        if(!turn[i + 1][j] && field[i + 1][j] != '.')
        {
            if(field[i + 1][j] == field[i][j])
            {
                turn[i + 1][j] = turn[i][j];
                scan({i + 1, j});
            }
            else
            {
                turn[i + 1][j] = turn[i][j] + 1;
                points.push({i + 1, j});
            }
        }
    }
    if(j != w - 1)
    {
        if(!turn[i][j + 1] && field[i][j + 1] != '.')
        {
            if(field[i][j + 1] == field[i][j])
            {
                turn[i][j + 1] = turn[i][j];
                scan({i, j + 1});
            }
            else
            {
                turn[i][j + 1] = turn[i][j] + 1;
                points.push({i, j + 1});
            }
        }
    }
}

int main()
{
    scanf("%d %d", &h, &w);
    
    field.assign(h, vector<char>(w));
    turn.assign(h, vector<int>(w, 0));
    
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            scanf(" %c", &field[i][j]);
    
    
    turn[0][0] = 1;
    points.push({0, 0});
    while(!points.empty())
    {
        answer = max(answer, turn[points.front().first][points.front().second]);
        scan(points.front());
    
        points.pop();
    }
    
    printf("%d\n", answer);
    
    return 0;
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:86:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |     scanf("%d %d", &h, &w);
      |     ~~~~~^~~~~~~~~~~~~~~~~
tracks.cpp:93:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |             scanf(" %c", &field[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1748 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 11 ms 2356 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 3 ms 824 KB Output is correct
12 Correct 7 ms 852 KB Output is correct
13 Correct 5 ms 820 KB Output is correct
14 Correct 5 ms 816 KB Output is correct
15 Correct 17 ms 1748 KB Output is correct
16 Correct 17 ms 1756 KB Output is correct
17 Correct 15 ms 1732 KB Output is correct
18 Correct 10 ms 2288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 980 KB Output is correct
2 Correct 107 ms 9140 KB Output is correct
3 Correct 791 ms 80628 KB Output is correct
4 Correct 184 ms 19504 KB Output is correct
5 Correct 491 ms 45844 KB Output is correct
6 Correct 1086 ms 141156 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 4 ms 980 KB Output is correct
9 Correct 4 ms 696 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 4 ms 1080 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 86 ms 8648 KB Output is correct
14 Correct 52 ms 5452 KB Output is correct
15 Correct 55 ms 5816 KB Output is correct
16 Correct 41 ms 4092 KB Output is correct
17 Correct 228 ms 21040 KB Output is correct
18 Correct 214 ms 20640 KB Output is correct
19 Correct 187 ms 19440 KB Output is correct
20 Correct 168 ms 17876 KB Output is correct
21 Correct 513 ms 47436 KB Output is correct
22 Correct 494 ms 45944 KB Output is correct
23 Correct 478 ms 39652 KB Output is correct
24 Correct 449 ms 46176 KB Output is correct
25 Correct 885 ms 80612 KB Output is correct
26 Correct 1129 ms 636720 KB Output is correct
27 Correct 1173 ms 351792 KB Output is correct
28 Correct 1067 ms 140964 KB Output is correct
29 Correct 1050 ms 143252 KB Output is correct
30 Correct 1065 ms 207676 KB Output is correct
31 Correct 688 ms 52320 KB Output is correct
32 Correct 1132 ms 343780 KB Output is correct