Submission #477918

#TimeUsernameProblemLanguageResultExecution timeMemory
477918Shogun3103Tracks in the Snow (BOI13_tracks)C++17
100 / 100
795 ms131140 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define FOR(i,a,b) for(__typeof(b) i=a; i<=b; i++) #define FOD(i,a,b) for(__typeof(b) i=b; i>=a; i--) #define EACH(u, v) for(auto& u : v) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define pb push_back #define pf push_front #define ii pair<int,int> #define iii pair<int,ii> #define f first #define s second #define ed "\n" #define sp " " #define vi vector<int> #define vii vector<ii> #define vl vector<ll> #define NO cout << "NO" << ed; #define YES cout << "YES" << ed; #define no cout << "no" << ed; #define yes cout << "yes" << ed; void setIO(string fileName = ""){ if(fileName.length()){ freopen((fileName+".in").c_str(), "r", stdin); freopen((fileName+".out").c_str(), "w", stdout); } } const int oo1 = 1e9 + 7; const int oo2 = 1e9 + 9; const int d4x[] = {0, 0, 1, -1}; const int d4y[] = {1, -1, 0, 0}; const int d8x[] = {-1, 0, 1, -1, 1, -1, 0, 1}; const int d8y[] = {1, 1, 1, 0, 0, -1, -1, -1}; const int N = 4000 + 10; const int M = 1e2 + 10; vi adj[N]; int n, m, dep[N][N]; char a[N][N]; bool ok(int x, int y) { return x && y && x <= n && y <= m && a[x][y] != '.'; } void solve() { cin >> n >> m; FOR(i, 1, n) FOR(j, 1, m) cin >> a[i][j]; int ans = 0; deque<ii> q; q.pb({1, 1}); dep[1][1] = 1; while(sz(q)) { ii cur = q.front(); q.pop_front(); ans = max(ans, dep[cur.f][cur.s]); FOR(i, 0, 3) { int x = cur.f + d4x[i]; int y = cur.s + d4y[i]; if(ok(x, y) && !dep[x][y]) { if(a[x][y] == a[cur.f][cur.s]) { dep[x][y] = dep[cur.f][cur.s]; q.pf({x, y}); } else { dep[x][y] = dep[cur.f][cur.s] + 1; q.pb({x, y}); } } } } cout << ans; } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); setIO(""); int t; t = 1; //int t; cin >> t; FOR(i, 1, t) { solve(); } return 0; }

Compilation message (stderr)

tracks.cpp: In function 'void setIO(std::string)':
tracks.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen((fileName+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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((fileName+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...