Submission #497144

#TimeUsernameProblemLanguageResultExecution timeMemory
497144viethoangphamTracks in the Snow (BOI13_tracks)C++17
100 / 100
1635 ms236236 KiB
#include<bits/stdc++.h>
#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define el "\n"
#define memset(a, x) memset(a, (x), sizeof(a));
#define sz(x) x.size()
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
const int INF = int(1e9) + 100;
const ll MAXN = (1 << 20) + 55;
const ll MOD = 1e6 + 3;
#define yes cout << "yes" << el;
#define no cout << "no" << el;
#define umap unordered_map
ll gcd(ll x, ll y){
    return !y?x:gcd(y,x%y);
}
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void setIO(str s) {
	setIn(s+".in"); setOut(s+".out");
}
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
ll n, m, ans = 0;
ll cnt[4005][4005];
char grid[4005][4005];
main(){
//    setIO("CodeforcesEasy");
    cin >> n >> m;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> grid[i][j];
        }
    }
    deque <pair<ll, ll>> q;
    q.push_front({0, 0});
    cnt[0][0] = 1;
    while (!q.empty()){
        auto temp = q.front();
        q.pop_front();
        ans = max(ans, cnt[temp.f][temp.s]);
        for (int i = 0; i < 4; i++){
            ll cx = temp.f + dx[i];
            ll cy = temp.s + dy[i];
            if (cx < 0 || cy < 0 || cx >= n || cy >= m || cnt[cx][cy] != 0 || grid[cx][cy] == '.') continue;
            if (grid[cx][cy] == grid[temp.f][temp.s]){
                q.push_front({cx, cy});
                cnt[cx][cy] = cnt[temp.f][temp.s];
            }else{
                q.push_back({cx, cy});
                cnt[cx][cy] = cnt[temp.f][temp.s] + 1;
            }
        }
    }
    cout << ans << el;
}

Compilation message (stderr)

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