Submission #441337

#TimeUsernameProblemLanguageResultExecution timeMemory
441337WindChaserTracks in the Snow (BOI13_tracks)C++11
0 / 100
117 ms68296 KiB
#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);
	}
}

//CSES messageRoute

int h, w;

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

char snow[4000][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++)
    {
        string s;
        
        cin >> s;

        for(int j = 0; j < w; j++)
        {
            snow[i][j] = s.at(j);
        }
        
    }

    deque<pair<int, int>> q;

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

    cout << ans;

    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 && 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 (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:73:16: warning: the address of 'bool valid(int, int)' will never be NULL [-Waddress]
   73 |             if(valid && numAni[nx][ny] == 0)
      |                ^~~~~
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);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...