답안 #766909

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
766909 2023-06-26T08:52:16 Z tamyte Tracks in the Snow (BOI13_tracks) C++14
100 / 100
534 ms 76184 KB
#include<bits/stdc++.h>
using namespace std;
void setIO(string name = "")
{
    cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
    if (name.size())
    {
        freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
        freopen((name + ".out").c_str(), "w", stdout);
    }
}
int n, m;

bool ok(int i, int j) {
    return min(i, j) >= 0 && i < n && j < m;
}

void solve() {
    cin >> n >> m;
    vector<vector<char>> arr(n, vector<char>(m));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> arr[i][j];
        }
    }
    vector<vector<bool>> vis(n, vector<bool>(m));
    int cnt = 1;
    deque<pair<int, int>> dq;
    dq.push_front({0, 0});
    vector<int> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
    char now = arr[0][0];
    while (dq.size()) {
        auto c = dq.front(); dq.pop_front();
        if (arr[c.first][c.second] != now) {
            now = arr[c.first][c.second];
            cnt++;
        }
        for (int i = 0; i < 4; ++i) {
            int ii = dy[i] + c.first;
            int jj = dx[i] + c.second;
            if (!ok(ii, jj) || vis[ii][jj] || arr[ii][jj] == '.') continue;
            vis[ii][jj] = true;
            if (arr[ii][jj] != now) {
                dq.push_back({ii, jj});
            } else {
                dq.push_front({ii, jj});
            }
        }
    }
    cout << cnt << "\n";
}


int main () {
    setIO();
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

Compilation message

tracks.cpp: In function 'void setIO(std::string)':
tracks.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:9:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 852 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 5 ms 852 KB Output is correct
5 Correct 2 ms 464 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 8 ms 920 KB Output is correct
16 Correct 9 ms 852 KB Output is correct
17 Correct 7 ms 812 KB Output is correct
18 Correct 5 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 836 KB Output is correct
2 Correct 37 ms 3672 KB Output is correct
3 Correct 256 ms 31048 KB Output is correct
4 Correct 75 ms 8396 KB Output is correct
5 Correct 145 ms 19172 KB Output is correct
6 Correct 534 ms 45240 KB Output is correct
7 Correct 2 ms 840 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 36 ms 3688 KB Output is correct
14 Correct 21 ms 2248 KB Output is correct
15 Correct 16 ms 2464 KB Output is correct
16 Correct 18 ms 1620 KB Output is correct
17 Correct 90 ms 8912 KB Output is correct
18 Correct 64 ms 8820 KB Output is correct
19 Correct 56 ms 8248 KB Output is correct
20 Correct 55 ms 7592 KB Output is correct
21 Correct 143 ms 19916 KB Output is correct
22 Correct 144 ms 19176 KB Output is correct
23 Correct 186 ms 16588 KB Output is correct
24 Correct 144 ms 19404 KB Output is correct
25 Correct 300 ms 31168 KB Output is correct
26 Correct 373 ms 76184 KB Output is correct
27 Correct 482 ms 66260 KB Output is correct
28 Correct 534 ms 45172 KB Output is correct
29 Correct 522 ms 43036 KB Output is correct
30 Correct 499 ms 50276 KB Output is correct
31 Correct 377 ms 22220 KB Output is correct
32 Correct 445 ms 55456 KB Output is correct