Submission #603702

# Submission time Handle Problem Language Result Execution time Memory
603702 2022-07-24T09:58:00 Z nguyen31hoang08minh2003 Zoo (COCI19_zoo) C++14
110 / 110
51 ms 3324 KB
/*
\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/
\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//
/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\
\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/
/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\
\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/
/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\
\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/
//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\
/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\
\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/\-\//\\//\\/-/
\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//\\--\//\\/--//
/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\/|\---\/---/|\
\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/\||\--/\--/||/
/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\/|||\//\\/|||\
\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/\|||/\\//\|||/
/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\/||/--\/--\||\
\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/\|/---/\---\|/
//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\//--/\\//\--\\
/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\/-/\\//\\//\-\
*/
#include <bits/stdc++.h>
#define fore(i, a, b) for (int i = (a), i##_last = (b); i < i##_last; ++i)
#define fort(i, a, b) for (int i = (a), i##_last = (b); i <= i##_last; ++i)
#define ford(i, a, b) for (int i = (a), i##_last = (b); i >= i##_last; --i)
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using ld = long double;

template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};
template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};

typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define maxR 1005
#define maxC 1005
const short directions[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};

int r, c;
string zoo[maxR];
bool seen[maxR][maxC];

void input() {
    cin >> r >> c;
    fore(x, 0, r)
        cin >> zoo[x];
}

void solve() {
    queue<ii> q[2];
    int res = 0;
    q[0].emplace(0, 0);
    seen[0][0] = true;
//    fore(x, 0, r)
//        cerr << zoo[x] << '\n';
    for (int i = 0, u, v; !q[i].empty(); i ^= 1) {
        ++res;
        for (; !q[i].empty(); q[i].pop()) {
            const auto &[x, y] = q[i].front();
            for (const auto &[dx, dy] : directions) {
                u = dx + x;
                v = dy + y;
                if (u < 0 || v < 0 || u >= r || v >= c || zoo[u][v] == '*' || seen[u][v])
                    continue;
                seen[u][v] = true;
                q[i ^ (zoo[u][v] != zoo[x][y])].emplace(u, v);
            }
        }
    }
    cout << res << '\n';
}

int main() {
    #ifdef LOCAL
        freopen("input.INP", "r", stdin);
    #endif // LOCAL
    cin.tie(0) -> sync_with_stdio(0);
    cout.tie(0);
    input();
    solve();
    return 0;
}

Compilation message

zoo.cpp: In function 'void solve()':
zoo.cpp:71:25: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   71 |             const auto &[x, y] = q[i].front();
      |                         ^
zoo.cpp:72:30: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   72 |             for (const auto &[dx, dy] : directions) {
      |                              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 7 ms 3200 KB Output is correct
17 Correct 7 ms 3284 KB Output is correct
18 Correct 6 ms 3284 KB Output is correct
19 Correct 8 ms 3324 KB Output is correct
20 Correct 7 ms 3284 KB Output is correct
21 Correct 43 ms 3092 KB Output is correct
22 Correct 42 ms 3156 KB Output is correct
23 Correct 38 ms 3224 KB Output is correct
24 Correct 41 ms 3284 KB Output is correct
25 Correct 38 ms 3284 KB Output is correct
26 Correct 39 ms 3168 KB Output is correct
27 Correct 44 ms 3156 KB Output is correct
28 Correct 40 ms 3156 KB Output is correct
29 Correct 44 ms 3304 KB Output is correct
30 Correct 51 ms 3180 KB Output is correct