답안 #943766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
943766 2024-03-11T20:47:33 Z sano Tracks in the Snow (BOI13_tracks) C++14
70.8333 / 100
824 ms 264800 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;
                    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()) {
      |                                                                         ~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2908 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Incorrect 6 ms 2464 KB Output isn't correct
5 Correct 4 ms 1112 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Incorrect 2 ms 1112 KB Output isn't correct
11 Incorrect 2 ms 856 KB Output isn't correct
12 Incorrect 4 ms 1372 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 2812 KB Output is correct
16 Correct 10 ms 2908 KB Output is correct
17 Correct 7 ms 2652 KB Output is correct
18 Incorrect 6 ms 2396 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1116 KB Output isn't correct
2 Incorrect 42 ms 15156 KB Output isn't correct
3 Incorrect 289 ms 149728 KB Output isn't correct
4 Correct 83 ms 35660 KB Output is correct
5 Correct 179 ms 84548 KB Output is correct
6 Correct 779 ms 187808 KB Output is correct
7 Correct 2 ms 1312 KB Output is correct
8 Incorrect 2 ms 1116 KB Output isn't correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
12 Correct 1 ms 684 KB Output is correct
13 Incorrect 40 ms 15192 KB Output isn't correct
14 Correct 23 ms 9052 KB Output is correct
15 Correct 21 ms 10076 KB Output is correct
16 Incorrect 22 ms 6560 KB Output isn't correct
17 Incorrect 106 ms 38480 KB Output isn't correct
18 Correct 97 ms 37968 KB Output is correct
19 Correct 79 ms 35648 KB Output is correct
20 Correct 69 ms 32904 KB Output is correct
21 Correct 165 ms 87376 KB Output is correct
22 Correct 183 ms 84308 KB Output is correct
23 Correct 212 ms 72968 KB Output is correct
24 Correct 165 ms 85328 KB Output is correct
25 Correct 629 ms 149872 KB Output is correct
26 Incorrect 824 ms 264800 KB Output isn't correct
27 Correct 801 ms 201584 KB Output is correct
28 Correct 755 ms 179596 KB Output is correct
29 Correct 745 ms 176348 KB Output is correct
30 Correct 747 ms 177828 KB Output is correct
31 Correct 433 ms 92188 KB Output is correct
32 Correct 758 ms 180060 KB Output is correct