結果
| 問題 |
No.307 最近色塗る問題多くない?
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2023-06-08 01:59:52 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 273 ms / 4,000 ms |
| コード長 | 1,444 bytes |
| コンパイル時間 | 4,381 ms |
| コンパイル使用メモリ | 141,108 KB |
| 実行使用メモリ | 9,344 KB |
| 最終ジャッジ日時 | 2024-12-30 07:46:08 |
| 合計ジャッジ時間 | 4,466 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 36 |
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
int g_visited[210][210];
int g_vid;
int A[210][210];
const int DY[4] = {-1, 0, 1, 0};
const int DX[4] = {0, 1, 0, -1};
int fill_x(int y, int x, int c, int nc) {
int cnt = 1;
g_visited[y][x] = g_vid;
A[y][x] = nc;
for (int dir = 0; dir < 4; ++dir) {
int ny = y + DY[dir];
int nx = x + DX[dir];
if (A[ny][nx] != c) continue;
cnt += fill_x(ny, nx, c, nc);
}
return cnt;
}
int main() {
g_vid = 0;
memset(g_visited, -1, sizeof(g_visited));
int H, W;
cin >> H >> W;
memset(A, -1, sizeof(A));
for (int y = 1; y <= H; ++y) {
for (int x = 1; x <= W; ++x) {
cin >> A[y][x];
}
}
int Q;
cin >> Q;
int max_cnt = 0;
int last_color = -1;
for (int i = 0; i < Q; ++i) {
int R, C, X;
cin >> R >> C >> X;
if (max_cnt == H * W) {
last_color = X;
continue;
}
if (A[R][C] == X) continue;
int cnt = fill_x(R, C, A[R][C], X);
max_cnt = max(max_cnt, cnt);
}
for (int y = 1; y <= H; ++y) {
for (int x = 1; x <= W; ++x) {
if (last_color != -1) {
cout << last_color;
} else {
cout << A[y][x];
}
if (x < W) cout << " ";
}
cout << endl;
}
return 0;
}
siman