답안 #441338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441338 2021-07-05T01:47:58 Z WindChaser Tracks in the Snow (BOI13_tracks) C++11
100 / 100
602 ms 118736 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define pb push_back

void setIO(string name = "") { 
	ios_base::sync_with_stdio(0); cin.tie(0); 

	if(name.size()){
		freopen((name+".in").c_str(), "r", stdin); 
		freopen((name+".out").c_str(), "w", stdout);
	}
}

//tracks in the Snow

int h, w;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

string snow[4000];

int numAni[4000][4000];

bool valid(int x, int y)
{
    return (x > -1 && x < h && y > -1 && y < w && snow[x][y] != '.');
}

int main()
{
    setIO();

    cin >> h >> w;

    for(int i = 0; i < h; i++)
    {
        cin >> snow[i];
        
    }

    deque<pair<int, int>> q;

    q.push_back({0,0});
    numAni[0][0] = 1;
    int ans = 1;

    while(!q.empty())
    {
        pair<int, int> c = q.front();
        q.pop_front();

        int curAni = numAni[c.first][c.second];

        ans = max(ans, curAni);

        for(int i = 0; i < 4; i++)
        {
            int nx = c.first + dx[i];
            int ny = c.second + dy[i];

            if(valid(nx, ny) && numAni[nx][ny] == 0)
            {
                if(snow[nx][ny] == snow[c.first][c.second])
                {
                    numAni[nx][ny] = curAni;
                    q.push_front({nx,ny}); 
                }
                else
                {
                    numAni[nx][ny] = curAni + 1;
                    q.push_back({nx,ny}); 
                }
            }
        }
    }

    cout << ans;

    return 0;

}

Compilation message

tracks.cpp: In function 'void setIO(std::string)':
tracks.cpp:11:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |   freopen((name+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:12:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |   freopen((name+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 3660 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 8 ms 3404 KB Output is correct
5 Correct 3 ms 1868 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 844 KB Output is correct
10 Correct 2 ms 1612 KB Output is correct
11 Correct 3 ms 1484 KB Output is correct
12 Correct 5 ms 2056 KB Output is correct
13 Correct 3 ms 1868 KB Output is correct
14 Correct 3 ms 1868 KB Output is correct
15 Correct 11 ms 3404 KB Output is correct
16 Correct 12 ms 3660 KB Output is correct
17 Correct 9 ms 3400 KB Output is correct
18 Correct 7 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 16100 KB Output is correct
2 Correct 40 ms 10348 KB Output is correct
3 Correct 188 ms 59808 KB Output is correct
4 Correct 71 ms 25628 KB Output is correct
5 Correct 155 ms 42516 KB Output is correct
6 Correct 598 ms 94340 KB Output is correct
7 Correct 12 ms 16972 KB Output is correct
8 Correct 12 ms 16076 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 12 ms 16204 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 43 ms 10300 KB Output is correct
14 Correct 22 ms 7056 KB Output is correct
15 Correct 20 ms 9292 KB Output is correct
16 Correct 21 ms 4292 KB Output is correct
17 Correct 100 ms 21188 KB Output is correct
18 Correct 86 ms 28432 KB Output is correct
19 Correct 68 ms 25668 KB Output is correct
20 Correct 50 ms 18916 KB Output is correct
21 Correct 119 ms 41516 KB Output is correct
22 Correct 157 ms 42392 KB Output is correct
23 Correct 197 ms 34896 KB Output is correct
24 Correct 122 ms 38400 KB Output is correct
25 Correct 460 ms 80700 KB Output is correct
26 Correct 353 ms 118736 KB Output is correct
27 Correct 460 ms 107228 KB Output is correct
28 Correct 602 ms 94236 KB Output is correct
29 Correct 580 ms 92604 KB Output is correct
30 Correct 532 ms 96988 KB Output is correct
31 Correct 568 ms 62088 KB Output is correct
32 Correct 401 ms 92536 KB Output is correct