結果
| 問題 |
No.307 最近色塗る問題多くない?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-28 21:52:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,950 bytes |
| コンパイル時間 | 891 ms |
| コンパイル使用メモリ | 95,444 KB |
| 実行使用メモリ | 814,296 KB |
| 最終ジャッジ日時 | 2024-09-14 05:00:09 |
| 合計ジャッジ時間 | 5,014 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 MLE * 1 -- * 31 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
typedef long long ll;
using namespace std;
inline int input(){
int a;
cin >> a;
return a;
}
template <typename T>
inline void output(T a, int p) {
if(p){
cout << fixed << setprecision(p) << a << "\n";
}
else{
cout << a << "\n";
}
}
// end of template
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
cin.tie(0);
// source code
int H = input();
int W = input();
vector<vector<int>> A(H, vector<int>(W));
rep(i, H){
rep(j, W){
cin >> A[i][j];
}
}
int Q;
cin >> Q;
int count = 0; // 盤面が変化した回数
rep(i, Q) {
int R, C, X;
cin >> R >> C >> X;
R--, C--;
if (count > H + W) break;
if (A[R][C] == X) continue;
// BFS
queue<pair<int, int>> q;
q.push(make_pair(R, C));
while (!q.empty()) {
var t = q.front();
q.pop();
A[t.first][t.second] = X;
rep(j, 4){
if (t.first + dy[j] >= 0 && t.first + dy[j] < H && t.second + dx[j] >= 0 && t.second + dx[j] < W && A[t.first + dy[j]][t.second + dx[j]] != X) { // 隣接している,かつXと違う色のマスを訪れる
q.push(make_pair(t.first + dy[j], t.second + dx[j]));
}
}
}
count++;
}
rep(i, H){
rep(j, W){
if (j) cout << " ";
cout << A[i][j];
}
cout << endl;
}
return 0;
}