답안 #961951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961951 2024-04-12T19:56:43 Z marinaluca Tracks in the Snow (BOI13_tracks) C++14
100 / 100
600 ms 239240 KB
#include <bits/stdc++.h>
 
#pragma GCC optimize ("O4")
#pragma GCC optimize ("fast-math")
#pragma GCC optimize ("unroll-loops")
 
using namespace std;
#define int long long
#define ll long long
#define XX first
#define YY second
#define all (x) begin(x), end(x)
/**
#define cin fin
#define cout fout
ifstream cin ("pfn.in");
ofstream cout ("pfn.out");
**/
typedef double dbl;
typedef long double ldb;
typedef pair <int, int> pii;
typedef vector <int> vii;
typedef pair <double, int> pdi;

const int SMAX = 10;
const int VMAX = 1;
const int RMAX = 179;
const int NMAX = 4e3;

int n, m;
char v[NMAX + 1][NMAX + 1];
int matrix[NMAX + 1][NMAX + 1];
struct elem {
    int x, y;
};

void read(){
    cin >> n >> m;
    for (int i = 1; i <= n; ++ i){
        for (int j = 1; j <= m; ++ j){
            cin >> v[i][j];
        }
    }
}

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
bool outmat (const elem &a){
    return a.x < 1 || a.x > n || a.y < 1 || a.y > m;
}

void solve (){
    int maxi = 1;
    matrix[1][1] = 1;
    deque <elem> pq;
    pq.push_front({1, 1});
    while (!pq.empty()){
        elem val = pq.front();
        pq.pop_front();
        maxi = max (maxi, matrix[val.x][val.y]);
        for (int i = 0; i < 4; ++ i){
            elem s = {val.x + dx[i], val.y + dy[i]};
            if (!outmat(s) && matrix[s.x][s.y] == 0 && v[s.x][s.y] != '.'){
                if (v[s.x][s.y] == v[val.x][val.y])
                {
                    matrix[s.x][s.y] = matrix[val.x][val.y];
                    pq.push_front(s);
                }
                else
                {
                    matrix[s.x][s.y] = matrix[val.x][val.y] + 1;
                    pq.push_back(s);
                }
            }
        }
    }
    cout << maxi;
}
signed main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int query = 1;
    while (query --){
        read();
        solve();
    }
    return 0 ^ 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8796 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 7 ms 8284 KB Output is correct
5 Correct 3 ms 6236 KB Output is correct
6 Correct 1 ms 4560 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 2 ms 4960 KB Output is correct
10 Correct 3 ms 5728 KB Output is correct
11 Correct 2 ms 5776 KB Output is correct
12 Correct 5 ms 6492 KB Output is correct
13 Correct 4 ms 6368 KB Output is correct
14 Correct 3 ms 6192 KB Output is correct
15 Correct 11 ms 8288 KB Output is correct
16 Correct 11 ms 8544 KB Output is correct
17 Correct 8 ms 8284 KB Output is correct
18 Correct 6 ms 8280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33120 KB Output is correct
2 Correct 40 ms 21524 KB Output is correct
3 Correct 246 ms 92372 KB Output is correct
4 Correct 85 ms 49480 KB Output is correct
5 Correct 163 ms 73912 KB Output is correct
6 Correct 573 ms 184092 KB Output is correct
7 Correct 11 ms 34140 KB Output is correct
8 Correct 12 ms 33116 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 16 ms 33744 KB Output is correct
12 Correct 2 ms 5352 KB Output is correct
13 Correct 45 ms 21592 KB Output is correct
14 Correct 34 ms 15104 KB Output is correct
15 Correct 22 ms 19284 KB Output is correct
16 Correct 18 ms 9996 KB Output is correct
17 Correct 112 ms 38972 KB Output is correct
18 Correct 100 ms 53816 KB Output is correct
19 Correct 85 ms 49496 KB Output is correct
20 Correct 69 ms 33596 KB Output is correct
21 Correct 162 ms 65188 KB Output is correct
22 Correct 158 ms 73900 KB Output is correct
23 Correct 217 ms 59880 KB Output is correct
24 Correct 160 ms 63828 KB Output is correct
25 Correct 473 ms 157040 KB Output is correct
26 Correct 348 ms 239240 KB Output is correct
27 Correct 485 ms 210052 KB Output is correct
28 Correct 583 ms 184212 KB Output is correct
29 Correct 600 ms 180888 KB Output is correct
30 Correct 577 ms 191436 KB Output is correct
31 Correct 458 ms 120996 KB Output is correct
32 Correct 445 ms 182220 KB Output is correct