Submission #694113

#TimeUsernameProblemLanguageResultExecution timeMemory
694113MarwenElarbiTracks in the Snow (BOI13_tracks)C++14
100 / 100
691 ms128772 KiB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define onbit __builtin_popcount
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
using namespace std;
const int MOD = 1e9+7;
const int nax = 1e6+2;
const int MAX_VAL = 1e6;
double PI=3.14159265359;
int arx[8]={1,1,0,-1,-1,-1, 0, 1};
int ary[8]={0,1,1, 1, 0,-1,-1,-1};
typedef complex<int> Point;
#define X real()
#define Y imag()
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
int n,m;
char tab[4005][4005];
bool inside(int x,int y)
{
    return (x>-1&&x<n&&y<m&&y>-1&&tab[x][y]!='.');
}
int main(){
    optimise;
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    //setIO("threesum");
    cin>>n>>m;
    int ans=1;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            cin>>tab[i][j];
        }
    }
    deque <pair<int,int>> dp;
    dp.push_front({0,0});
    int depth[n][m];
    memset(depth,0,sizeof depth);
    depth[0][0]=1;
    while (!dp.empty())
    {
        int x=dp.front().fi;
        int y=dp.front().se;
        dp.pop_front();
        for (int i = 0; i < 7; i+=2)
        {
            int a=x+arx[i],b=y+ary[i];
            //cout <<" "<<x<<" "<<y<<endl;
            if (inside(a,b)&&depth[a][b]==0)
            {
                if (tab[x][y]==tab[a][b])
                {
                    depth[a][b]=depth[x][y];
                    dp.push_front({a,b});
                }else{
                    depth[a][b]=depth[x][y]+1;
                    ans=max(depth[a][b],ans);
                    dp.push_back({a,b});
                    //cout << depth[a][b]<<" "<<depth[x][y]<<endl;
                }
            }
        }//cout << dp.size()<<endl;
    }
    cout << ans<<endl;
}   

Compilation message (stderr)

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