Submission #943765

# Submission time Handle Problem Language Result Execution time Memory
943765 2024-03-11T20:46:03 Z sano Tracks in the Snow (BOI13_tracks) C++17
57.7083 / 100
863 ms 258644 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 + 1;
                    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 + 1;
                    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 Incorrect 0 ms 344 KB Output isn't correct
4 Incorrect 6 ms 2396 KB Output isn't correct
5 Correct 2 ms 1116 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 2 ms 860 KB Output isn't correct
11 Incorrect 2 ms 860 KB Output isn't correct
12 Incorrect 5 ms 1344 KB Output isn't correct
13 Correct 2 ms 1116 KB Output is correct
14 Correct 2 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 Incorrect 6 ms 2396 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1116 KB Output isn't correct
2 Incorrect 39 ms 14340 KB Output isn't correct
3 Incorrect 293 ms 141680 KB Output isn't correct
4 Incorrect 79 ms 33604 KB Output isn't correct
5 Correct 170 ms 79960 KB Output is correct
6 Correct 773 ms 179636 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Incorrect 2 ms 1116 KB Output isn't correct
9 Correct 2 ms 856 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Incorrect 2 ms 1116 KB Output isn't correct
12 Correct 1 ms 600 KB Output is correct
13 Incorrect 40 ms 14172 KB Output isn't correct
14 Correct 25 ms 8468 KB Output is correct
15 Incorrect 20 ms 9308 KB Output isn't correct
16 Incorrect 20 ms 5976 KB Output isn't correct
17 Incorrect 104 ms 36320 KB Output isn't correct
18 Incorrect 95 ms 35832 KB Output isn't correct
19 Incorrect 77 ms 33368 KB Output isn't correct
20 Correct 70 ms 30868 KB Output is correct
21 Correct 164 ms 82704 KB Output is correct
22 Correct 170 ms 79696 KB Output is correct
23 Correct 209 ms 68952 KB Output is correct
24 Correct 165 ms 80752 KB Output is correct
25 Correct 644 ms 141680 KB Output is correct
26 Incorrect 863 ms 258644 KB Output isn't correct
27 Correct 842 ms 209996 KB Output is correct
28 Correct 811 ms 187740 KB Output is correct
29 Correct 795 ms 184484 KB Output is correct
30 Correct 767 ms 185756 KB Output is correct
31 Incorrect 458 ms 97344 KB Output isn't correct
32 Correct 805 ms 188320 KB Output is correct