Submission #634115

# Submission time Handle Problem Language Result Execution time Memory
634115 2022-08-23T20:19:09 Z atom Tracks in the Snow (BOI13_tracks) C++17
100 / 100
800 ms 131176 KB
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, b) for(int i = 0; i < b; i++)
#define PER(i, b) for(int i = b - 1; i >= 0; i--)
#define fi first
#define se second
#define all(x) x.begin(), x.end()

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#define debugArr(...) 42
#endif

const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAX = 4005;

int n, m;
char a[MAX][MAX];
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
int d[MAX][MAX];


bool isInside(int x, int y){
    return (1 <= x && x <= n && 1 <= y && y <= m && a[x][y] != '.');
}

void run_case(){
	cin >> n >> m;
    FOR(i, 1, n) FOR(j, 1, m) cin >> a[i][j];
    int ans = 1;
    deque<pii> q;
    q.push_front({1, 1});
    d[1][1] = 1;
    while (!q.empty()){
        auto [x, y] = q.front();
        q.pop_front();
        ckmax(ans, d[x][y]);
        REP(i, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (isInside(nx, ny) && d[nx][ny] == 0){
                if (a[x][y] == a[nx][ny]){
                    d[nx][ny] = d[x][y];
                    q.push_front({nx, ny});
                }
                else {
                    d[nx][ny] = d[x][y] + 1;
                    q.push_back({nx, ny});
                }
            }
        }
    }
	cout << ans << "\n";
}

signed main(){
    cin.tie(0) -> sync_with_stdio(0);

    int Test = 1;
    //cin >> Test;
    FOR(i, 1, Test){

        run_case();
    }
}
// Codename : Jasper the Otter

# Verdict Execution time Memory Grader output
1 Correct 12 ms 5460 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 8 ms 5200 KB Output is correct
5 Correct 3 ms 2900 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 728 KB Output is correct
8 Correct 1 ms 836 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 3 ms 2516 KB Output is correct
11 Correct 3 ms 2200 KB Output is correct
12 Correct 5 ms 3032 KB Output is correct
13 Correct 4 ms 2896 KB Output is correct
14 Correct 4 ms 2900 KB Output is correct
15 Correct 12 ms 5268 KB Output is correct
16 Correct 12 ms 5460 KB Output is correct
17 Correct 9 ms 5204 KB Output is correct
18 Correct 8 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 30748 KB Output is correct
2 Correct 51 ms 15060 KB Output is correct
3 Correct 332 ms 73332 KB Output is correct
4 Correct 92 ms 32712 KB Output is correct
5 Correct 218 ms 53276 KB Output is correct
6 Correct 711 ms 108688 KB Output is correct
7 Correct 16 ms 32212 KB Output is correct
8 Correct 16 ms 30816 KB Output is correct
9 Correct 3 ms 660 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 18 ms 31580 KB Output is correct
12 Correct 2 ms 1616 KB Output is correct
13 Correct 49 ms 15008 KB Output is correct
14 Correct 27 ms 10444 KB Output is correct
15 Correct 34 ms 13032 KB Output is correct
16 Correct 23 ms 5608 KB Output is correct
17 Correct 119 ms 28716 KB Output is correct
18 Correct 113 ms 35660 KB Output is correct
19 Correct 89 ms 32700 KB Output is correct
20 Correct 73 ms 25456 KB Output is correct
21 Correct 189 ms 52556 KB Output is correct
22 Correct 209 ms 53380 KB Output is correct
23 Correct 223 ms 43756 KB Output is correct
24 Correct 187 ms 49880 KB Output is correct
25 Correct 491 ms 94260 KB Output is correct
26 Correct 766 ms 131176 KB Output is correct
27 Correct 710 ms 122340 KB Output is correct
28 Correct 727 ms 108836 KB Output is correct
29 Correct 800 ms 106972 KB Output is correct
30 Correct 707 ms 112104 KB Output is correct
31 Correct 472 ms 73448 KB Output is correct
32 Correct 708 ms 114232 KB Output is correct