Submission #1020063

#TimeUsernameProblemLanguageResultExecution timeMemory
10200637againTracks in the Snow (BOI13_tracks)C++17
0 / 100
2089 ms164764 KiB
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define FAST ios::sync_with_stdio(0);cout.tie(0);cin.tie(0)

using namespace std ;

void setIO(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}

const int N = 6e3 , MOD = 1e9+7 ;
int xis[4]{1 , -1 , 0 , 0} , yis[4]{0 , 0 , 1 , -1} ;

int n , m ;
char a[N][N] ;
vector <int> v[N] ;

bool inside(int x , int y)
{
    return (x < n && x > -1 && y < m && y > -1 && a[x][y] != '.') ;
}
void slv()
{
    cin >> n >> m ;
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < m ; j++)
            cin >> a[i][j] ;

    int depth[n][m]{0} ;
    deque <pair <int , int>> q ;
    q.push_back({0 , 0}) ;
    depth[0][0] = 1 ;
    int mx = 1 ;

    while(q.size())
    {
        pair <int , int> t = q.front() ;
        q.pop_front() ;

        mx = max(mx , depth[t.f][t.s]) ;

        for(int i = 0 ; i < 4 ; i++)
        {
            int x = t.f + xis[i] , y = t.s = yis[i] ;
            if(inside(x , y) && depth[x][y] == 0)
            {
                if(a[x][y] == a[t.f][t.s])
                {
                    depth[x][y] = depth[t.f][t.s] ;
                    q.push_front({x , y}) ;
                }
                else
                {
                    depth[x][y] = depth[t.f][t.s] + 1 ;
                    q.push_back({x , y}) ;
                }
            }
        }
    }


    cout << mx + 1 ;
}
main()
{
    FAST ;

    slv() ;
}

Compilation message (stderr)

tracks.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main()
      | ^~~~
tracks.cpp: In function 'void setIO(std::string)':
tracks.cpp:10:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 | void setIO(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:10:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 | void setIO(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...