Submission #854727

# Submission time Handle Problem Language Result Execution time Memory
854727 2023-09-28T16:13:48 Z vjudge1 Paint (COI20_paint) C++17
8 / 100
3000 ms 14420 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;
        if (c == a[ix][iy])
            continue;
        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: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 ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
paint.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen(taskname ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 316 ms 944 KB Output is correct
6 Correct 507 ms 1136 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2396 KB Output is correct
2 Correct 168 ms 4028 KB Output is correct
3 Execution timed out 3061 ms 10556 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2490 ms 14420 KB Output is correct
2 Correct 384 ms 9812 KB Output is correct
3 Correct 514 ms 14304 KB Output is correct
4 Execution timed out 3060 ms 9792 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 106 ms 4688 KB Output is correct
2 Execution timed out 3075 ms 5476 KB Time limit exceeded
3 Halted 0 ms 0 KB -