Submission #916660

#TimeUsernameProblemLanguageResultExecution timeMemory
916660May27_thTracks in the Snow (BOI13_tracks)C++17
19.79 / 100
766 ms142356 KiB
#include <bits/stdc++.h> #define int64_t long long #define double long double using namespace std; using type = int64_t; const long long mod = 1000000007, inf = 1e18; const int base = 33; const int N = 2e5 + 10; const int LG = 20; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; void Minimize(int64_t &a, int64_t b) {if(b < a) a = b;} void Maximize(int &a, int b) {if(b > a) a = b;} void Add(int64_t& a, int64_t b) {a = a + b; a %= mod;} void Dec(int64_t& a, int64_t b) {a = a - b + mod; a %= mod;} int h, w; char g[4010][4010]; int d[4005][4005]; void Solve(void) { cin >> h >> w; for(int i = 1; i <= h; i ++){ for(int j = 1; j <= w; j ++){ cin >> g[i][j]; d[i][j] = 1e9; } } deque<pair<int, int>>q; d[1][1] = 1; q.push_front(make_pair(1, 1)); while(!q.empty()){ int u = q.front().first; int v = q.front().second; q.pop_front(); for(int i = 0; i < 4; i ++){ int nu = u + dx[i]; int nv = v + dy[i]; if(nu >= 1 && nv >= 1 && nu <= h && nv <= w){ int weight = (g[u][v] != g[nu][nv]); if(g[nu][nv] == '.') weight = 0; if(d[nu][nv] > d[u][v] + weight){ d[nu][nv] = d[u][v] + weight; //cout << d[nu][nv] << "\n"; if(weight == 1) q.push_back(make_pair(nu, nv)); else q.push_front(make_pair(nu, nv)); } } } } int ans = 0; for(int i = 1; i <= h; i ++){ for(int j = 1; j <= w; j ++){ //cout << d[i][j] << " "; ans = max(ans, d[i][j]); } //cout << "\n"; } cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); if(fopen("poetry.in", "r")){ freopen("poetry.in", "r", stdin); freopen("poetry.out", "w", stdout); } if(fopen("A.inp", "r")){ freopen("A.inp", "r", stdin); freopen("A.out", "w", stdout); } int tc = 1; //cin >> tc; while(tc --){ Solve(); } }

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen("poetry.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen("poetry.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen("A.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
tracks.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen("A.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...