Submission #466967

# Submission time Handle Problem Language Result Execution time Memory
466967 2021-08-21T05:36:12 Z mithilshah23 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
687 ms 235896 KB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#define ll long long
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < n; i++)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)
#define ff first
#define ss second
#define in(azz, sz)                 \
    for (int ix = 0; ix < sz; ix++) \
        cin >> azz[ix];
#define in2d(azz, row, column) rep(i, row) rep(j, column) cin >> azz[i][j];
#define out2d(azz, row, column)                  \
    rep(i, row)                                  \
    {                                            \
        rep(j, column) cout << azz[i][j] << " "; \
        cout << "\n"                             \
    };
#define out(azz, sz)                \
    for (int ix = 0; ix < sz; ix++) \
    {                               \
        cout << azz[ix] << " ";     \
    }                               \
    cout << endl
#define mii map<int, int>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define endl '\n'
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define ALL(a) a.begin(), a.end()
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ps(x, y) fixed << setprecision(y) << x
#define mp make_pair
#define all(vx) vx.begin(), vx.end()
#define maxv(azz) max_element(all(azz)) - azz.begin() //return index of max element of vector;
#define minv(azz) min_element(all(azz)) - azz.begin() //return index of min element of vector;
#define maxa(azz) max_element(azz, azz + n) - azz     //return index of max element of array, n==size of array;
#define mina(azz) min_element(azz, azz + n) - azz     //return index of min element of array, n==size of array;
#define isort(azz) is_sorted(all(azz))                //check if elements are sorted;
#define setpres cout.precision(numeric_limits<double>::max_digits10);
#define rev(vx) reverse(all(vx))
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef set<int> seti;
#define am(a, b) MOD(MOD(a) + MOD(b))
#define mm(a, b) MOD(MOD(a) * MOD(b))
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
const ll INF = 1000000007;
ll MOD(ll a)
{
    a = a % INF;
    while (a < 0)
        a += INF;
    return a;
}

ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = mm(res, a);
        a = mm(a, a);
        b >>= 1;
    }
    return res;
}
ll modInverse(ll a)
{
    return binpow(a, INF - 2);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                DON'T MAKE CHANGES BEFORE THIS LINE!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#define int ll //use only if needed;
int depth[5000][5000];
int n = 4000, m = 4000;
int ans = -1;
int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};
string snow[4000];
bool inside(int x, int y)
{
    return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.');
}

void tosolve()
{
    cin >> n >> m;
    rep(i, n) cin >> snow[i];
    deque<pair<int, int>> q;
    q.push_back({0, 0});
    depth[0][0] = 1;

    while (q.size())
    {
        pair<int, int> c = q.front();
        q.pop_front();
        ans = max(ans, depth[c.first][c.second]);

        for (int i = 0; i < 4; i++)
        {
            int x = c.first + dx[i], y = c.second + dy[i];
            if (inside(x, y) && depth[x][y] == 0)
            {
                if (snow[x][y] == snow[c.first][c.second])
                {
                    depth[x][y] = depth[c.first][c.second];
                    q.push_front({x, y});
                }
                else
                {
                    depth[x][y] = depth[c.first][c.second] + 1;
                    q.push_back({x, y});
                }
            }
        }
    }
    cout << ans << endl;
    return;
}

int32_t main()
{
    fastio

    {
        tosolve();
    }
    return 0;
}
/*

███╗░░░███╗██╗████████╗██╗░░██╗██╗██╗░░░░░
████╗░████║██║╚══██╔══╝██║░░██║██║██║░░░░░
██╔████╔██║██║░░░██║░░░███████║██║██║░░░░░
██║╚██╔╝██║██║░░░██║░░░██╔══██║██║██║░░░░░
██║░╚═╝░██║██║░░░██║░░░██║░░██║██║███████╗
╚═╝░░░░░╚═╝╚═╝░░░╚═╝░░░╚═╝░░╚═╝╚═╝╚══════╝

 *  Author : mithilshah23
 *  Website : Oj
 *  Problem : track in the snow
 *  Time : 21-08-2021 11:00:52
 *  Lang : GNU C++17
 */
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4812 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 8 ms 4352 KB Output is correct
5 Correct 3 ms 2252 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 844 KB Output is correct
10 Correct 3 ms 1868 KB Output is correct
11 Correct 3 ms 1740 KB Output is correct
12 Correct 5 ms 2508 KB Output is correct
13 Correct 3 ms 2252 KB Output is correct
14 Correct 3 ms 2252 KB Output is correct
15 Correct 11 ms 4488 KB Output is correct
16 Correct 14 ms 4916 KB Output is correct
17 Correct 9 ms 4596 KB Output is correct
18 Correct 8 ms 4324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16204 KB Output is correct
2 Correct 41 ms 15096 KB Output is correct
3 Correct 199 ms 94780 KB Output is correct
4 Correct 78 ms 43164 KB Output is correct
5 Correct 179 ms 69312 KB Output is correct
6 Correct 678 ms 202168 KB Output is correct
7 Correct 12 ms 16836 KB Output is correct
8 Correct 11 ms 16204 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 11 ms 16588 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 42 ms 15084 KB Output is correct
14 Correct 23 ms 9832 KB Output is correct
15 Correct 27 ms 14336 KB Output is correct
16 Correct 20 ms 6460 KB Output is correct
17 Correct 110 ms 33004 KB Output is correct
18 Correct 94 ms 47812 KB Output is correct
19 Correct 74 ms 43148 KB Output is correct
20 Correct 54 ms 27144 KB Output is correct
21 Correct 129 ms 61152 KB Output is correct
22 Correct 172 ms 69448 KB Output is correct
23 Correct 206 ms 56096 KB Output is correct
24 Correct 127 ms 59332 KB Output is correct
25 Correct 551 ms 174852 KB Output is correct
26 Correct 413 ms 235896 KB Output is correct
27 Correct 554 ms 228220 KB Output is correct
28 Correct 671 ms 202260 KB Output is correct
29 Correct 687 ms 198952 KB Output is correct
30 Correct 613 ms 207212 KB Output is correct
31 Correct 549 ms 115388 KB Output is correct
32 Correct 477 ms 199396 KB Output is correct