답안 #1053898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053898 2024-08-11T20:44:23 Z catsarecool5530 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
372 ms 124128 KB
//#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define endl "\n"
const ll MOD = 1e9 + 7;
void setIO() { freopen("input.in", "r", stdin); }
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

int dirx[4]{0, 1, 0, -1};
int diry[4]{1, 0, -1, 0};
int n, m;
vector<string> snow;
bool inside(int x, int y) {
	return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.');
}

void solve() {
   
    cin >> n >> m;
    snow = vector<string> (n);
    for (string& i : snow) cin >> i;

    int ans = 0;
    vector<vector<int>> depth(n, vector<int>(m));
    depth[0][0] = 1;
    
    deque<array<int, 2>> de;
    de.push_back({0, 0});
    while (!de.empty()) {
        auto [x, y] = de.front();
        de.pop_front();
        ans = max(depth[x][y], ans);
        for (int i = 0; i < 4; i++) {
            if (!inside(x + dirx[i], y + diry[i])) continue;
            if (depth[x + dirx[i]][y + diry[i]] != 0) continue;
            if (snow[x][y] == snow[x + dirx[i]][y + diry[i]]) {
                depth[x + dirx[i]][y + diry[i]] = depth[x][y];
                de.push_front({x + dirx[i], y + diry[i]});
            } else {
                depth[x + dirx[i]][y + diry[i]] = depth[x][y] + 1;
                de.push_back({x + dirx[i], y + diry[i]});
            }
        }   
    }
    cout << ans << endl;



}
 
 
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    //setIO();

    ll t = 1; //cin >> t;
    while (t--) {
        solve();
    }
}

Compilation message

tracks.cpp: In function 'void setIO()':
tracks.cpp:8:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 | void setIO() { freopen("input.in", "r", stdin); }
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp: In function 'void setIO(std::string)':
tracks.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:11:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1880 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 3 ms 1628 KB Output is correct
5 Correct 1 ms 984 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 868 KB Output is correct
11 Correct 1 ms 912 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 5 ms 2000 KB Output is correct
16 Correct 6 ms 1884 KB Output is correct
17 Correct 4 ms 1912 KB Output is correct
18 Correct 3 ms 1488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 21 ms 9736 KB Output is correct
3 Correct 110 ms 96596 KB Output is correct
4 Correct 37 ms 22876 KB Output is correct
5 Correct 78 ms 54300 KB Output is correct
6 Correct 372 ms 111032 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 788 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 1112 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 19 ms 9816 KB Output is correct
14 Correct 12 ms 5896 KB Output is correct
15 Correct 9 ms 6236 KB Output is correct
16 Correct 11 ms 4188 KB Output is correct
17 Correct 57 ms 24668 KB Output is correct
18 Correct 32 ms 24156 KB Output is correct
19 Correct 35 ms 22636 KB Output is correct
20 Correct 27 ms 20828 KB Output is correct
21 Correct 67 ms 56264 KB Output is correct
22 Correct 76 ms 54404 KB Output is correct
23 Correct 114 ms 46676 KB Output is correct
24 Correct 66 ms 54732 KB Output is correct
25 Correct 157 ms 96712 KB Output is correct
26 Correct 264 ms 124128 KB Output is correct
27 Correct 281 ms 122172 KB Output is correct
28 Correct 356 ms 111036 KB Output is correct
29 Correct 356 ms 108280 KB Output is correct
30 Correct 316 ms 113204 KB Output is correct
31 Correct 258 ms 62288 KB Output is correct
32 Correct 270 ms 120544 KB Output is correct