結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー |
![]() |
提出日時 | 2015-11-28 00:45:10 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 141 ms / 4,000 ms |
コード長 | 2,166 bytes |
コンパイル時間 | 869 ms |
コンパイル使用メモリ | 95,044 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-21 21:56:32 |
合計ジャッジ時間 | 2,665 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
ソースコード
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <utility> #include <memory> #include <functional> #include <deque> #include <cctype> #include <numeric> #include <ctime> #include <bitset> #include <cctype> #include <vector> #include <map> #include <set> #include <stack> #include <queue> #include <cstring> #include <string> #include <sstream> #include <algorithm> #include <iomanip> using namespace std; //define #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; #define dump(x) cerr << #x << " = " << (x) << endl; #define INF (INT_MAX/2) #define PI (2*acos(0.0)) #define EPS (1e-8) #define REP(i,a,b) for(int i=(a); i<(b);++i) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vint; typedef vector<vector<int> > vvint; typedef vector<ll> vll; typedef vector<vector<ll> > vvll; int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1}; int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int H, W; int cnt_zero; vvint A; void dfs(int r, int c, int x){ int color = A[r][c]; A[r][c] = x; if(color == 0 && A[r][c] == 1) cnt_zero--; if(color == 1 && A[r][c] == 0) cnt_zero++; for(int i = 0; i < 4; i++){ int nr = r + dy[i]; int nc = c + dx[i]; if(0 <= nr && nr < H && 0 <= nc && nc < W && A[nr][nc] == color && A[nr][nc] != x){ dfs(nr, nc, x); } } } int main(void){ ios_base::sync_with_stdio(0); cin >> H >> W; A = vvint(H); int input; rep(i, H){ rep(j, W){ cin >> input; if(input == 0) cnt_zero++; A[i].push_back(input); } } int Q, R, C, X; int all = -1; cin >> Q; rep(i, Q){ cin >> R >> C >> X; R--; C--; if(cnt_zero != H * W && cnt_zero != 0) dfs(R, C, X); else all = X; } if(all == -1){ rep(i, H){ rep(j, W){ if(j) cout << " "; cout << A[i][j]; } cout << endl; } }else{ rep(i, H){ rep(j, W){ if(j) cout << " "; cout << all; } cout << endl; } } return 0; }