Submission #1015809

# Submission time Handle Problem Language Result Execution time Memory
1015809 2024-07-06T20:31:31 Z lucascgar Tracks in the Snow (BOI13_tracks) C++17
100 / 100
468 ms 155284 KB
#include <bits/stdc++.h>

// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using namespace std;

/*
two puddles of the same type are intersected by one with connection to start, then its all 2 animals only

começo no início
    - tudo q eu percorrer é 1 bicho só, todos os diferentes adjacentes a ele são do mesmo bicho só, e assim por diante

*/

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // overclock random

typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, double> pdd;

const int MAXN = 4e3+12;


char g[MAXN][MAXN];

int d[MAXN][MAXN], aux[4] = {1, -1, 0, 0};

signed main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // freopen("test.in", "r", stdin);
    // freopen("test.out", "w", stdout);
    // cout << fixed << setprecision(12);

    int n, m;
    cin >> n >> m;
    for (int i=1;i<=n;i++) for (int j=1;j<=m;j++){
        cin >> g[i][j];
        d[i][j] = 1e9;
        if (g[i][j] == '.') d[i][j] = -1;
    }

    // priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<>> q;

    deque<pair<int, pii>> q;

    q.push_back({1, {1,1}});
    d[1][1] = 1;
    int ans=1;

    while (!q.empty()){
        auto u = q.front();
        q.pop_front();

        if (u.first != d[u.second.first][u.second.second]) continue;
        
        if (u.first>ans) ans=u.first;
        pii x = u.second;
        char t = g[x.first][x.second];

        for (int a=0,b=3;a<4;a++,b--){
            int ni = x.first+aux[a],nj=x.second+aux[b];
            if (d[ni][nj] == -1) continue;

            int nd = u.first + (t != g[ni][nj]);

            if (d[ni][nj] <= nd) continue;

            d[ni][nj] = nd;

            if (nd == u.first) q.push_front({nd, {ni,nj}});
            else q.push_back({nd, {ni, nj}});
        }

    }

    cout << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6876 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 5 ms 5340 KB Output is correct
5 Correct 3 ms 3164 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 3 ms 3420 KB Output is correct
12 Correct 4 ms 4420 KB Output is correct
13 Correct 3 ms 4444 KB Output is correct
14 Correct 3 ms 3192 KB Output is correct
15 Correct 8 ms 6748 KB Output is correct
16 Correct 9 ms 6780 KB Output is correct
17 Correct 8 ms 6568 KB Output is correct
18 Correct 6 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 32348 KB Output is correct
2 Correct 37 ms 19292 KB Output is correct
3 Correct 228 ms 94732 KB Output is correct
4 Correct 77 ms 34900 KB Output is correct
5 Correct 188 ms 68540 KB Output is correct
6 Correct 465 ms 113356 KB Output is correct
7 Correct 13 ms 33372 KB Output is correct
8 Correct 14 ms 33628 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 12 ms 31832 KB Output is correct
12 Correct 1 ms 1628 KB Output is correct
13 Correct 38 ms 18060 KB Output is correct
14 Correct 21 ms 12124 KB Output is correct
15 Correct 20 ms 13144 KB Output is correct
16 Correct 17 ms 8028 KB Output is correct
17 Correct 92 ms 37452 KB Output is correct
18 Correct 87 ms 36948 KB Output is correct
19 Correct 76 ms 34692 KB Output is correct
20 Correct 56 ms 32336 KB Output is correct
21 Correct 146 ms 70980 KB Output is correct
22 Correct 156 ms 68760 KB Output is correct
23 Correct 174 ms 57856 KB Output is correct
24 Correct 139 ms 69968 KB Output is correct
25 Correct 291 ms 93496 KB Output is correct
26 Correct 327 ms 155284 KB Output is correct
27 Correct 394 ms 123204 KB Output is correct
28 Correct 457 ms 111312 KB Output is correct
29 Correct 468 ms 108772 KB Output is correct
30 Correct 411 ms 114768 KB Output is correct
31 Correct 330 ms 73044 KB Output is correct
32 Correct 341 ms 110440 KB Output is correct