답안 #381554

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381554 2021-03-25T09:50:16 Z Araragi Paint (COI20_paint) C++17
0 / 100
12 ms 1260 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("00")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
ll time() {return chrono::system_clock().now().time_since_epoch().count();}
mt19937 rnd(time());
const int inf = 1e9;
const ll inf64 = 1e18;
#define ft first
#define fin(x) ifstream cin("x.in");
#define fout(x) ofstream cout("x.out");
#define sd second
#define pb push_back
#define sz(x) (int)x.size()

int steps[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

string grid[10001];
bool bad[10001][10001];
int n, m;

void dfs(int x, int y, char who, char to)
{
    if (bad[x][y] || x < 0 || x >= n || y >= n || y < 0)
        return;

    grid[x][y] = to;

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

        if (cx < 0 || cy < 0 || cx >= n || cy >= n)
            continue;

        if (grid[cx][cy] == who)
            dfs(cx, cy, who, to);
    }
}

void solve()
{
    cin >> n >> m;

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> grid[i][j];

    int q;
    cin >> q;

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

        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                bad[i][j] = false;

        dfs(x, y, grid[x][y], to);
    }

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

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

    #ifdef _LOCAL_
        system("color a");
    #endif // _LOCAL_

    int t = 1;

    while (t--)
        solve();

}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1132 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 1260 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1132 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1132 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -