Submission #1053898

#TimeUsernameProblemLanguageResultExecution timeMemory
1053898catsarecool5530Tracks in the Snow (BOI13_tracks)C++17
100 / 100
372 ms124128 KiB
//#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define endl "\n"
const ll MOD = 1e9 + 7;
void setIO() { freopen("input.in", "r", stdin); }
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

int dirx[4]{0, 1, 0, -1};
int diry[4]{1, 0, -1, 0};
int n, m;
vector<string> snow;
bool inside(int x, int y) {
	return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.');
}

void solve() {
   
    cin >> n >> m;
    snow = vector<string> (n);
    for (string& i : snow) cin >> i;

    int ans = 0;
    vector<vector<int>> depth(n, vector<int>(m));
    depth[0][0] = 1;
    
    deque<array<int, 2>> de;
    de.push_back({0, 0});
    while (!de.empty()) {
        auto [x, y] = de.front();
        de.pop_front();
        ans = max(depth[x][y], ans);
        for (int i = 0; i < 4; i++) {
            if (!inside(x + dirx[i], y + diry[i])) continue;
            if (depth[x + dirx[i]][y + diry[i]] != 0) continue;
            if (snow[x][y] == snow[x + dirx[i]][y + diry[i]]) {
                depth[x + dirx[i]][y + diry[i]] = depth[x][y];
                de.push_front({x + dirx[i], y + diry[i]});
            } else {
                depth[x + dirx[i]][y + diry[i]] = depth[x][y] + 1;
                de.push_back({x + dirx[i], y + diry[i]});
            }
        }   
    }
    cout << ans << endl;



}
 
 
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    //setIO();

    ll t = 1; //cin >> t;
    while (t--) {
        solve();
    }
}

Compilation message (stderr)

tracks.cpp: In function 'void setIO()':
tracks.cpp:8:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 | void setIO() { freopen("input.in", "r", stdin); }
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp: In function 'void setIO(std::string)':
tracks.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:11:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...