답안 #758766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758766 2023-06-15T09:09:16 Z fanwen Zoo (COCI19_zoo) C++17
110 / 110
44 ms 6228 KB
/**
 *      author : pham van sam 
 *      created : 14 June 2023 (Wednesday)
 **/

#include <bits/stdc++.h>

using namespace std;
using namespace chrono;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)

template <typename U, typename V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <typename U, typename V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }

const int MAXN = 1e3 + 5;
const int dir[] = {1, -1, 0, 0, 0, 0, 1, -1};

int N, M, dp[MAXN][MAXN];
char a[MAXN][MAXN];

void process(void) {
    cin >> N >> M;
    FOR(i, 1, N) FOR(j, 1, M) cin >> a[i][j];
    deque <pair <int, int>> q;
    memset(dp, 0x3f, sizeof dp);
    q.emplace_front(1, 1); dp[1][1] = 1;
    while(!q.empty()) {
        auto [u, v] = q.front(); q.pop_front();
        REP(i, 4) {
            int x = u + dir[i];
            int y = v + dir[i + 4];
            if(x < 1 || x > N || y < 1 || y > M) continue;
            if(a[x][y] == '*') continue;
            int cost = (a[x][y] != a[u][v] ? 1 : 0);
            if(minimize(dp[x][y], dp[u][v] + cost)) {
                if(!cost) q.emplace_front(x, y);
                else q.emplace_back(x, y);
            }
        }
    }
    int ans = 0;
    FOR(i, 1, N) FOR(j, 1, M) if(a[i][j] != '*') {
        maximize(ans, dp[i][j]);
    }
    cout << ans;
}

signed main() {

    #define TASK "TASK"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    auto start_time = steady_clock::now();
    int test = 1;
    // cin >> test;
    for (int i = 1; i <= test; ++i) {
        process();
        // cout << '\n';
    }

    auto end_time = steady_clock::now();

    cerr << "\nExecution time : " << duration_cast<milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

Compilation message

zoo.cpp: In function 'int main()':
zoo.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
zoo.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 3 ms 4312 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 2 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 3 ms 4312 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 2 ms 4308 KB Output is correct
16 Correct 13 ms 6224 KB Output is correct
17 Correct 14 ms 6140 KB Output is correct
18 Correct 19 ms 6180 KB Output is correct
19 Correct 15 ms 6228 KB Output is correct
20 Correct 17 ms 6192 KB Output is correct
21 Correct 43 ms 6068 KB Output is correct
22 Correct 40 ms 6124 KB Output is correct
23 Correct 38 ms 6164 KB Output is correct
24 Correct 44 ms 6228 KB Output is correct
25 Correct 40 ms 6100 KB Output is correct
26 Correct 41 ms 6164 KB Output is correct
27 Correct 40 ms 6148 KB Output is correct
28 Correct 42 ms 6132 KB Output is correct
29 Correct 40 ms 6196 KB Output is correct
30 Correct 40 ms 6192 KB Output is correct