제출 #444002

#제출 시각아이디문제언어결과실행 시간메모리
444002hackerbhaiyaTracks in the Snow (BOI13_tracks)C++14
100 / 100
951 ms112924 KiB
#include<bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC optimize("no-stack-protector")
// #define ll __int128
#define ll long long
// #define ll int
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
// #define mod 998244353 
#define mp make_pair
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define ff first
#define ss second
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sc(a) scanf("%lld",&a)
#define pf printf
#define sz(a) (int)(a.size())
#define psf push_front
#define ppf pop_front
#define ppb pop_back
#define pb push_back
#define pq priority_queue
#define all(s) s.begin(),s.end()
#define sp(a) setprecision(a)
#define rz resize
#define ld long double
#define inf (ll)1e18
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define eb emplace_back
const double pi = acos(-1);
ll binpow(ll a, ll b){ll res=1;while(b!=0){if(b&1)res*=a;a*=a;b>>=1;}return res;}
// ll binpow(ll a, ll b, ll md){ll res=1;a%=mod;while(b!=0){if(b&1)res*=a,res%=md;a*=a,a%=md;b>>=1;}return res%md;}
 
using namespace std;

int n,m;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
vector<string> s;

bool check(int x, int y)
{
    if(x>=0 && y>=0 && x<n && y<m && s[x][y]!='.')
        return 1;
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("xortransform.in","r",stdin);
    // freopen("xortransform.out","w",stdout);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt","r",stdin);
//     freopen("output.txt","w",stdout);
// #endif
    int z=1;
    // cin>>z;
    f(i,1,z+1)
    {
        int ans=1;
        cin>>n>>m;
        s.rz(n);
        f(i,0,n)
            cin>>s[i];
        vector<vector<int> > dis(n,vector<int> (m,INT_MAX));
        deque<pair<int,int> > q;
        q.psf({0,0}); 
        dis[0][0]=1;
        while(!q.empty())
        {
            auto temp=q.front();
            q.pop_front();
            int x=temp.ff,y=temp.ss;
            f(i,0,4)
            {
                int xx=x+dx[i],yy=y+dy[i];
                if(check(xx,yy))
                {
                    if(s[xx][yy]!=s[x][y] && dis[xx][yy]>dis[x][y]+1)
                    {
                        dis[xx][yy]=1+dis[x][y];
                        ans=max(ans,dis[xx][yy]);
                        q.pb({xx,yy});
                    }
                    else if(s[xx][yy]==s[x][y] && dis[xx][yy]>dis[x][y])
                    {
                        dis[xx][yy]=dis[x][y];
                        ans=max(ans,dis[xx][yy]);
                        q.psf({xx,yy});
                    }
                }
            }
        }
        cout<<ans<<"\n";      
    }
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...