답안 #854724

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854724 2023-09-28T16:04:36 Z vjudge1 Paint (COI20_paint) C++17
0 / 100
340 ms 524288 KB
#define taskname ""
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifndef LOCAL
#define cerr \
    if (0)   \
    cerr
#endif

const bool multitest = 0;

// Subtask 1: Simple Query DFS

const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int r, s;
vector<vector<int>> a;

void DFS(int x, int y, int color, int precolor)
{
    if (!(x >= 1 && x <= r && y >= 1 && y <= s) || (a[x][y] != precolor))
        return;
    a[x][y] = color;
    for (int i = 0; i < 4; i++)
    {
        int nx = x + dx[i], ny = y + dy[i];
        DFS(nx, ny, color, precolor);
    }
}

void solve()
{
    cin >> r >> s;
    a.assign(r + 3, vector<int>(s + 3));
    for (int i = 1; i <= r; i++)
        for (int j = 1; j <= s; j++)
            cin >> a[i][j];
    int q;
    cin >> q;
    while (q--)
    {
        int ix, iy, c;
        cin >> ix >> iy >> c;
        DFS(ix, iy, c, a[ix][iy]);
    }
    for (int i = 1; i <= r; i++, cout << '\n')
        for (int j = 1; j <= s; j++)
            cout << a[i][j] << ' ';
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen(taskname ".inp", "r"))
    {
        freopen(taskname ".inp", "r", stdin);
        freopen(taskname ".out", "w", stdout);
    }
    int tc = 1;
    if (multitest)
        cin >> tc;
    while (tc--)
    {
        solve();
        cout << '\n';
    }
}

Compilation message

paint.cpp: In function 'int32_t main()':
paint.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(taskname ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
paint.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(taskname ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 332 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 328 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 327 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 340 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -