結果

問題 No.307 最近色塗る問題多くない?
ユーザー uenokuuenoku
提出日時 2017-01-14 02:56:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,963 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 92,372 KB
実行使用メモリ 9,620 KB
最終ジャッジ日時 2023-08-23 10:28:08
合計ジャッジ時間 7,115 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,620 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 556 ms
4,376 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "math.h"
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define ifor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long double ld;
typedef long long int lli;
typedef complex<double> P;
const double eps = 1e-11;
int vx[4] = {1, 0, -1, 0};
int vy[4] = {0, 1, 0, -1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
lli MOD = 1000000007;
int h, w;
bool inrange(int x, int y)
{
    return 0 <= x && x < h && y < w && 0 <= y;
}
int f[205][205];

bool used[300][300];
int temp[300][300];
void dfs(int x, int y, int from, int c)
{
    if (used[x][y])
        return;
    temp[x][y] = c;
    used[x][y] = true;
    rep(i, 4)
    {
        int nx = vx[i] + x;
        int ny = vy[i] + y;
        if (inrange(nx, ny)) {
            if (f[nx][ny] == from && !used[nx][ny])
                dfs(nx, ny, from, c);
        }
    }
};

int main()
{
    cin >> h >> w;
    int a, b, c;
    rep(i, h) rep(j, w) cin >> f[i][j];
    int q;
    cin >> q;
    rep(m, q)
    {
        cin >> a >> b >> c;
        a--, b--;
        rep(i, h) rep(j, w)
        {
            used[i][j] = false;
            temp[i][j] = f[i][j];
        }
        dfs(a, b, f[a][b], c);
        rep(i, h) rep(j, w) f[i][j] = temp[i][j];
        // rep(i, h) rep(j, w)
        // {
        //     cout << f[i][j];
        //     if (j == w - 1)
        //         cout << endl;
        //     else
        //         cout << ' ';
        // }
        // cout << endl;
    }
    rep(i, h) rep(j, w)
    {
        cout << f[i][j];
        if (j == w - 1)
            cout << endl;
        else
            cout << ' ';
    }
}
0