답안 #381360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381360 2021-03-25T07:00:45 Z NONAME Paint (COI20_paint) C++17
0 / 100
16 ms 2540 KB
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, const T b) {a = min(a, b); return (a == b);}
template <typename T> inline bool chmax(T& a, const T b) {a = max(a, b); return (a == b);}

const int steps[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int man = (int)(2e5 + 500);

int n, m;
int a[man];
bool was[man];

int to(int x, int y) {
    return (x * m) + y;
}

int btool(int x, int y, int c) {
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            was[to(i, j)] = false;
        }
    }

    queue <array <int, 2> > q;
    q.push({x, y});
    was[to(x, y)] = true;
    while (!q.empty()) {
        auto cur = q.front();
        q.pop();

        for (int i = 0; i < 4; ++i) {
            int cx = cur[0] + steps[i][0];
            int cy = cur[1] + steps[i][1];

            if ((cx >= 0) && (cx < n) && (cy >= 0) && (cy < m) && !was[to(cx, cy)] && (a[to(cx, cy)] == a[to(x, y)])) {
                was[to(cx, cy)] = true;
                q.push({cx, cy});
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            a[to(i, j)] = (was[to(i, j)] ? c : a[to(i, j)]);
        }
    }
}

void solve() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a[to(i, j)];
        }
    }

    int q;
    cin >> q;
    while (q--) {
        int x, y, c;
        cin >> x >> y >> c;
        --x, --y;

        btool(x, y, c);
    }

    for (int i = 0; i < n; ++i, cout << "\n") {
        for (int j = 0; j < m; ++j) {
            cout << a[to(i, j)] << " ";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #ifdef _LOCAL
        system("color a");
        freopen("in.txt", "r", stdin);
    #endif

    solve();

    return 0;
}

Compilation message

paint.cpp: In function 'int btool(int, int, int)':
paint.cpp:48:1: warning: no return statement in function returning non-void [-Wreturn-type]
   48 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 620 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1004 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 2540 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 1900 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -