Submission #443704

#TimeUsernameProblemLanguageResultExecution timeMemory
443704BeanZTracks in the Snow (BOI13_tracks)C++14
82.50 / 100
2096 ms351472 KiB
// I_Love_LPL 1y0m2d #include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 4005; long long mod = 1000007; const int lim = 4e5 + 5; const int lg = 20; const int base = 311; const long double eps = 1e-6; ll nx[4] = {0, 0, 1, -1}; ll ny[4] = {1, -1, 0, 0}; char a[N][N]; ll dp[N][N]; struct viet{ ll x, y, v; bool operator <(const viet &o) const{ return v > o.v; } }; ll n, m; bool check(ll x, ll y){ if (x < 1 || x > n || y < 1 || y > m || a[x][y] == '.') return false; else return true; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("tests.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } cin >> n >> m; for (int i = 1; i <= n; i++){ for (int j = 1; j <= m; j++){ cin >> a[i][j]; dp[i][j] = 1e18; } } priority_queue<viet> q; q.push({1, 1, 1}); dp[1][1] = 1; ll ans = 1; while (q.size()){ viet x = q.top(); ans = max(ans, x.v); q.pop(); for (int i = 0; i < 4; i++){ ll nwx = x.x + nx[i]; ll nwy = x.y + ny[i]; if (!check(nwx, nwy)) continue; ll cost = x.v + (a[nwx][nwy] != a[x.x][x.y]); if (dp[nwx][nwy] > cost){ dp[nwx][nwy] = cost; q.push({nwx, nwy, cost}); } } } cout << ans; } /* Ans: Out: */

Compilation message (stderr)

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