Submission #943767

# Submission time Handle Problem Language Result Execution time Memory
943767 2024-03-11T20:48:33 Z sano Tracks in the Snow (BOI13_tracks) C++14
100 / 100
798 ms 257080 KB
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <random>
#include <stack>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <queue>
#include <map>
//#include <popcntintrin.h> // Include the header file for __builtin_popcount
#define ll long long
#define For(i, n) for(ll i = 0; i < n; ++i)
#define ffor(i, a, n) for(ll i = a; i < n; ++i)
#define pb push_back
#define vec vector 
#define ff first
#define ss second
#define pairs pair<ll, ll>
#define NEK 1000000000
#define mod 1000000007
using namespace std;
typedef unsigned short int sui;

vec<vec<ll>> d;
ll naj = -1;
struct tr {
    ll x, y, w;
};

void BFS(vec<vec<char>>&p) {
    deque<tr> q;
    d[0][0] = 0;
    q.push_back({ 0, 0, 0 });
    while (!q.empty()) {
        tr x = q.front();
        q.pop_front();
        for (ll j = -1; j <= 1; j += 2) {
            if ((x.x) >= 0 && (x.x) < p.size() && (x.y + j) >= 0 && (x.y + j) < p[0].size()) {
                if (p[x.x][x.y + j] == '.') continue;
                if (d[x.x][x.y + j] != -1) continue;
                if (p[x.x][x.y + j] != p[x.x][x.y]) {
                    q.push_back({ x.x, x.y + j, x.w + 1 });
                    d[x.x][x.y + j] = x.w + 1;
                    naj = max(naj, d[x.x][x.y + j]);
                }
                else {
                    q.push_front({ x.x, x.y + j, x.w });
                    d[x.x][x.y + j] = x.w;
                    naj = max(naj, d[x.x][x.y + j]);
                }
            }
        }
        for (ll i = -1; i <= 1; i += 2) {
            if ((x.x + i) >= 0 && (x.x + i) < p.size() && (x.y) >= 0 && (x.y) < p[0].size()) {
                if (p[x.x + i][x.y] == '.') continue;
                if (d[x.x + i][x.y] != -1) continue;
                if (p[x.x + i][x.y] != p[x.x][x.y]) {
                    q.push_back({ x.x + i, x.y, x.w + 1 });
                    d[x.x + i][x.y] = x.w + 1;
                    naj = max(naj, d[x.x + i][x.y]);
                }
                else {
                    q.push_front({ x.x + i, x.y, x.w });
                    d[x.x + i][x.y] = x.w;
                    naj = max(naj, d[x.x + i][x.y]);
                }
            }
        }
    }
    return;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream cin("subrev.in");
    //ofstream cout("subrev.out");
    ll h, w;
    cin >> h >> w;
    vec<vec<char>> p(h, vec<char>(w));
    d.resize(h, vec<ll>(w, -1));
    For(i, h) {
        For(j, w) {
            cin >> p[i][j];
        }
    }
    BFS(p);
    cout << naj+1 << '\n';
    return 0;
}

Compilation message

tracks.cpp: In function 'void BFS(std::vector<std::vector<char> >&)':
tracks.cpp:42:37: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             if ((x.x) >= 0 && (x.x) < p.size() && (x.y + j) >= 0 && (x.y + j) < p[0].size()) {
      |                               ~~~~~~^~~~~~~~~~
tracks.cpp:42:79: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             if ((x.x) >= 0 && (x.x) < p.size() && (x.y + j) >= 0 && (x.y + j) < p[0].size()) {
      |                                                                     ~~~~~~~~~~^~~~~~~~~~~~~
tracks.cpp:58:45: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             if ((x.x + i) >= 0 && (x.x + i) < p.size() && (x.y) >= 0 && (x.y) < p[0].size()) {
      |                                   ~~~~~~~~~~^~~~~~~~~~
tracks.cpp:58:79: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             if ((x.x + i) >= 0 && (x.x + i) < p.size() && (x.y) >= 0 && (x.y) < p[0].size()) {
      |                                                                         ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2652 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 6 ms 2396 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 2 ms 1116 KB Output is correct
14 Correct 3 ms 1116 KB Output is correct
15 Correct 9 ms 2652 KB Output is correct
16 Correct 10 ms 2652 KB Output is correct
17 Correct 7 ms 2396 KB Output is correct
18 Correct 6 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 41 ms 14328 KB Output is correct
3 Correct 282 ms 141680 KB Output is correct
4 Correct 86 ms 33616 KB Output is correct
5 Correct 171 ms 79928 KB Output is correct
6 Correct 766 ms 179616 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 49 ms 14312 KB Output is correct
14 Correct 29 ms 8480 KB Output is correct
15 Correct 28 ms 9308 KB Output is correct
16 Correct 19 ms 5980 KB Output is correct
17 Correct 112 ms 36356 KB Output is correct
18 Correct 96 ms 35672 KB Output is correct
19 Correct 80 ms 33368 KB Output is correct
20 Correct 66 ms 30868 KB Output is correct
21 Correct 164 ms 82524 KB Output is correct
22 Correct 173 ms 79708 KB Output is correct
23 Correct 205 ms 68960 KB Output is correct
24 Correct 162 ms 80752 KB Output is correct
25 Correct 613 ms 141912 KB Output is correct
26 Correct 798 ms 257080 KB Output is correct
27 Correct 784 ms 200636 KB Output is correct
28 Correct 768 ms 179612 KB Output is correct
29 Correct 747 ms 176500 KB Output is correct
30 Correct 742 ms 178140 KB Output is correct
31 Correct 435 ms 92244 KB Output is correct
32 Correct 752 ms 179824 KB Output is correct