Submission #1185500

#TimeUsernameProblemLanguageResultExecution timeMemory
1185500Vivek_03_Tracks in the Snow (BOI13_tracks)C++20
100 / 100
496 ms112156 KiB
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<set> #include<map> #include<deque> #include<unordered_map> #include<cstdio> using namespace std; #ifndef LOCAL #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("avx2,popcnt") #endif #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define pb push_back #define ppb pop_back #define mp make_pair typedef long long ll; typedef unsigned long long ull; typedef long double lld; #ifndef ONLINE_JUDGE #define debug(x) cerr << #x <<" "; _print(x); cerr << endl; #else #define debug(x) #endif void _print(ll t) {cerr << t;} void _print(int t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(lld t) {cerr << t;} void _print(double t) {cerr << t;} void _print(ull t) {cerr << t;} void _print(pair<int,int> t) {cerr << t.first << ' '<<t.second;} template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T> void _print(multiset <T> v); template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(unordered_map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} int main() { fastio(); #ifndef ONLINE_JUDGE freopen("Error.txt", "w", stderr); #endif int n,m; cin>>n>>m; vector<string> v(n); for(int i=0;i<n;i++) { cin>>v[i]; } vector<vector<int>> dist(n, vector<int>(m,1e9)); vector<int> di = {1,0,-1,0,1}; dist[0][0] = 1; deque<pair<int,int>> dq; dq.push_back({0,0}); int ans = 1; while(!dq.empty()) { int x = dq.front().first, y = dq.front().second; dq.pop_front(); ans = max(ans, dist[x][y]); for(int i=0;i<4;i++) { int nx = x + di[i], ny = y + di[i+1]; if(nx<0 || ny<0 || nx>=n || ny>=m || v[nx][ny]=='.') continue; int wt = (v[x][y] != v[nx][ny]); if(dist[x][y] + wt < dist[nx][ny]) { dist[nx][ny] = dist[x][y] + wt; if(wt) dq.push_back({nx,ny}); else dq.push_front({nx,ny}); } } } cout<<ans<<'\n'; }

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen("Error.txt", "w", stderr);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...