結果

問題 No.307 最近色塗る問題多くない?
ユーザー Yang33Yang33
提出日時 2018-09-30 13:32:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 146 ms / 4,000 ms
コード長 3,133 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 176,228 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-12 09:03:14
合計ジャッジ時間 3,772 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9; const LL LINF = 1e16;
const LL MOD = 1000000007; const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- 2018/09/30 Problem: yukicoder 307 / Link: http://yukicoder.me/problems/no/307 ----- */
/* ------------
HW2
RC(R,C) (1,1)(H,W)
(R,C)AR,C
(R,C)(R′,C′)2 (R,C)(R′,C′)
(R,C)(R′,C′)(R′,C′)(R′′,C′′) (R,C)(R′′,C′′)
(R,C)(R′,C′) 1 (R′,C′) (R+1,C),(R−1,C),(R,C+1),(R,C−1
    )
(R,C) X Q
Q
---------- */
/* ----------
-------- */
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int H, W; cin >> H >> W;
VVI a(H, VI(W));
FOR(i, 0, H) {
FOR(j, 0, W) {
cin >> a[i][j];
}
}
int Q; cin >> Q;
int f = 0;
FOR(i, 0, Q) {
int r, c, x; cin >> r >> c >> x;
r--, c--;
// comp(r,c) = x
if (a[r][c] == x || (f&&i != Q - 1))continue;
if (f && i == Q - 1) {
a = VVI(H, VI(W, x)); break;
}
int cnt = 1;
queue<PII>q;
a[r][c] = x;
q.push(PII(r, c));
while (!q.empty()) {
PII pos = q.front(); q.pop();
FOR(k, 0, 4) {
int ny = pos.first + DY[k], nx = pos.second + DX[k];
if (0 <= ny && ny < H && 0 <= nx && nx < W) {
if (a[ny][nx] != x) {
a[ny][nx] = x;
cnt++;
q.push(PII(ny, nx));
}
}
}
}
if (cnt == H * W)f = 1;
}
FOR(i, 0, H) {
FOR(j, 0, W) {
cout << a[i][j] << " \n"[j == W - 1];
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0