Submission #1075303

# Submission time Handle Problem Language Result Execution time Memory
1075303 2024-08-26T01:36:59 Z Yang8on Tracks in the Snow (BOI13_tracks) C++14
100 / 100
550 ms 131140 KB
#include <bits/stdc++.h>
#define Y8o "Tracks in the Snow"
#define maxn (int) 4005
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r

//#define f first
//#define s second

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
    if(fopen(Y8o".inp", "r"))
    {
        freopen(Y8o".inp", "r", stdin);
//        freopen(Y8o".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}
void ctime() {
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

int m, n, ans;
char a[maxn][maxn];
int dp[maxn][maxn];
bool exist(int u, int v) { return 1 <= u && u <= m && 1 <= v && v <= n && a[u][v] != '.'; }

void solve() {
    cin >> m >> n ;
    for(int i = 1; i <= m; i ++) for(int j = 1; j <= n; j ++)
        cin >> a[i][j] ;

    deque<pii> q;
    q.push_back({ 1, 1 });
    dp[1][1] = 1;

    while(q.size()) {
        int i, j; tie(i, j) = q.front();
        q.pop_front();

        ans = max(ans, dp[i][j]);

        for(int t = 0; t <= 3; t ++) {
            int u = i + dx[t], v = j + dy[t];
            if(exist(u, v) && dp[u][v] == 0) {
                if(a[u][v] == a[i][j]) {
                    dp[u][v] = dp[i][j];
                    q.push_front({ u, v });
                }
                else {
                    dp[u][v] = dp[i][j] + 1;
                    q.push_back({ u, v });
                }
            }
        }
    }

    cout << ans;
}


int main() {
    iof();

    int nTest = 1;
//    cin >> nTest;

    while(nTest --) {
        solve();
    }

    ctime();
    return 0;
}

Compilation message

tracks.cpp: In function 'void iof()':
tracks.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 5508 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 6 ms 5300 KB Output is correct
5 Correct 4 ms 3080 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 2 ms 2136 KB Output is correct
12 Correct 5 ms 3164 KB Output is correct
13 Correct 3 ms 2908 KB Output is correct
14 Correct 3 ms 2908 KB Output is correct
15 Correct 9 ms 5340 KB Output is correct
16 Correct 11 ms 5604 KB Output is correct
17 Correct 10 ms 5212 KB Output is correct
18 Correct 8 ms 5148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 30812 KB Output is correct
2 Correct 37 ms 15156 KB Output is correct
3 Correct 260 ms 73492 KB Output is correct
4 Correct 70 ms 32804 KB Output is correct
5 Correct 177 ms 53332 KB Output is correct
6 Correct 519 ms 107872 KB Output is correct
7 Correct 12 ms 32264 KB Output is correct
8 Correct 12 ms 30812 KB Output is correct
9 Correct 2 ms 856 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 14 ms 31580 KB Output is correct
12 Correct 2 ms 1624 KB Output is correct
13 Correct 39 ms 15128 KB Output is correct
14 Correct 28 ms 10588 KB Output is correct
15 Correct 22 ms 13208 KB Output is correct
16 Correct 17 ms 5840 KB Output is correct
17 Correct 102 ms 28752 KB Output is correct
18 Correct 73 ms 35696 KB Output is correct
19 Correct 71 ms 32880 KB Output is correct
20 Correct 60 ms 25428 KB Output is correct
21 Correct 143 ms 52728 KB Output is correct
22 Correct 164 ms 53340 KB Output is correct
23 Correct 179 ms 43924 KB Output is correct
24 Correct 142 ms 49744 KB Output is correct
25 Correct 318 ms 94440 KB Output is correct
26 Correct 305 ms 131140 KB Output is correct
27 Correct 420 ms 121040 KB Output is correct
28 Correct 550 ms 107960 KB Output is correct
29 Correct 515 ms 106340 KB Output is correct
30 Correct 457 ms 110404 KB Output is correct
31 Correct 399 ms 73556 KB Output is correct
32 Correct 374 ms 106288 KB Output is correct