Submission #682640

#TimeUsernameProblemLanguageResultExecution timeMemory
682640AmmarTracks in the Snow (BOI13_tracks)C++17
100 / 100
800 ms121580 KiB
#include <bits/stdc++.h> #include<iostream> #include<iomanip> #include<algorithm> #include<vector> #include<utility> #include<set> #include<unordered_set> #include<list> #include<iterator> #include<deque> #include<queue> #include<stack> #include<set> #include<bitset> #include<random> #include<map> #include<unordered_map> #include<stdio.h> #include<complex> #include<math.h> #include<cstring> #include<chrono> #include<string> // #pragma GCC optimize("Ofast") // #pragma GCC optimize("no-stack-protector") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") // #pragma GCC optimize("fast-math") using namespace std; #define pb push_back #define ff first #define ss second #define vi vector <int> #define vvi vector <vi> #define pii pair<int, int> #define ppi pair<pii, int> #define vii vector<pii> #define mii map<int, int> #define mci map<char, int> #define miv map<int, vi> #define mis map<int, set<int>> #define setbits(n) __builtin_popcount(n) #define all(v) (v).begin(), (v).end() #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl #define endl "\n" #define fo(i,n) for(int i=0;i<n;i++) #define in(a,n) for(int i=0;i<n;i++) cin>>a[i]; #define show2(a, b) cout<<a<<' '<<b<<endl #define show3(a, b, c) cout<<a<<' '<<b<<' '<<c<<endl #define show(arr) for (auto i:arr) cout<<i<<' '; #define Endl endl const long long N=1e7+5; const long long mod=1000000007; //998244353; int n,m,ans; string s[4005]; vvi d; int a[]={-1,0,0,1}; int b[]={0,-1,1,0}; bool inrange(int x, int y) { return x>=0 && x<n && y>=0 && y<m && s[x][y]!='.'; } void bfs() { deque<pii> q; q.pb(pii({0,0})); d[0][0]=1; while(q.size()) { auto p=q.front();q.pop_front(); int x=p.ff,y=p.ss; ans=max(ans,d[x][y]); for(int k=0;k<4;k++) { int u=x+a[k],v=y+b[k]; if(inrange(u,v)) { if(s[u][v]!=s[x][y] && d[u][v]>1+d[x][y]) { d[u][v]=1+d[x][y];q.pb({u,v}); } else if(s[u][v]==s[x][y] && d[u][v]>d[x][y]) { d[u][v]=d[x][y];q.push_front({u,v}); } } } } } void cases(){ cin>>n>>m;ans=1; for(int i=0;i<n;i++)cin>>s[i]; d.assign(n,vi(m,N)); bfs(); cout<<ans<<endl; } int32_t main(){ std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int t=1; // cin>>t; for (int i=0; i<t; i++){ //cout<<"Case #"<<i+1<<": "; cases(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...