답안 #1078626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078626 2024-08-28T01:26:32 Z Yang8on Tracks in the Snow (BOI13_tracks) C++17
100 / 100
506 ms 131172 KB
#include <bits/stdc++.h>
#define Y8o "main"
#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 m, n;
char a[maxn][maxn];
int dp[maxn][maxn];

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
bool exist(int u, int v) {
    return 1 <= u && u <= m && 1 <= v && v <= n && a[u][v] != '.';
}

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

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

        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 });
                }
            }
        }
    }
}
void solve() {
    cin >> m >> n ;
    for(int i = 1; i <= m; i ++) for(int j = 1; j <= n; j ++)
        cin >> a[i][j] ;

    bfs();

    int ans = 0;
    for(int i = 1; i <= m; i ++) for(int j = 1; j <= n; j ++)
        ans = max(ans, dp[i][j]);
    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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 5468 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 6 ms 5212 KB Output is correct
5 Correct 3 ms 2908 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 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 2140 KB Output is correct
12 Correct 4 ms 3164 KB Output is correct
13 Correct 3 ms 3040 KB Output is correct
14 Correct 3 ms 2908 KB Output is correct
15 Correct 9 ms 5212 KB Output is correct
16 Correct 11 ms 5384 KB Output is correct
17 Correct 9 ms 5364 KB Output is correct
18 Correct 7 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 30812 KB Output is correct
2 Correct 44 ms 15184 KB Output is correct
3 Correct 245 ms 73280 KB Output is correct
4 Correct 80 ms 32848 KB Output is correct
5 Correct 176 ms 53460 KB Output is correct
6 Correct 506 ms 107880 KB Output is correct
7 Correct 14 ms 32348 KB Output is correct
8 Correct 14 ms 30812 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 14 ms 31604 KB Output is correct
12 Correct 2 ms 1628 KB Output is correct
13 Correct 38 ms 15060 KB Output is correct
14 Correct 24 ms 10580 KB Output is correct
15 Correct 20 ms 13148 KB Output is correct
16 Correct 17 ms 5744 KB Output is correct
17 Correct 99 ms 28728 KB Output is correct
18 Correct 76 ms 35596 KB Output is correct
19 Correct 76 ms 32712 KB Output is correct
20 Correct 57 ms 25512 KB Output is correct
21 Correct 146 ms 52552 KB Output is correct
22 Correct 163 ms 53264 KB Output is correct
23 Correct 184 ms 43860 KB Output is correct
24 Correct 143 ms 49744 KB Output is correct
25 Correct 344 ms 94292 KB Output is correct
26 Correct 303 ms 131172 KB Output is correct
27 Correct 378 ms 116064 KB Output is correct
28 Correct 501 ms 107856 KB Output is correct
29 Correct 495 ms 106136 KB Output is correct
30 Correct 479 ms 109000 KB Output is correct
31 Correct 393 ms 73440 KB Output is correct
32 Correct 340 ms 105740 KB Output is correct