結果
問題 | No.179 塗り分け |
ユーザー |
![]() |
提出日時 | 2015-04-08 15:56:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 148 ms / 3,000 ms |
コード長 | 1,741 bytes |
コンパイル時間 | 773 ms |
コンパイル使用メモリ | 86,460 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-23 14:28:23 |
合計ジャッジ時間 | 3,159 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 40 |
ソースコード
#include <algorithm> #include <vector> #include <cfloat> #include <string> #include <cmath> #include <set> #include <cstdlib> #include <map> #include <ctime> #include <iomanip> #include <functional> #include <deque> #include <iostream> #include <cstring> #include <queue> #include <cstdio> #include <stack> #include <climits> #include <sys/time.h> #include <cctype> using namespace std; typedef long long ll; int main() { int h, w; cin >> h >> w; string str[h]; for (int i = 0; i < h; i++) { cin >> str[i]; } int cnt = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cnt += (str[i][j] == '#'); } } if (cnt%2) { std::cout << "NO" << std::endl; return 0; } bool memo[2*h+1][2*w+1]; memset(memo, false, sizeof(memo)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { bool goout = false; if (str[i][j] == '#') { for (int k = 0; k < h; k++) { for (int l = 0; l < w; l++) { if (i == k && j == l) continue; if (str[i][j] == '#') { memo[k-i+h][l-j+w] = true; } } } } } } for (int i = 0; i < 2*h+1; i++) { for (int j = 0; j < 2*w+1; j++) { if (memo[i][j]) { int tcnt = 0; bool vis[h][w]; memset(vis, false, sizeof(vis)); for (int k = 0; k < h; k++) { for (int l = 0; l < w; l++) { if (str[k][l] != '#' || vis[k][l]) { continue; } vis[k][l] = true; int ny = k+i-h, nx = l+j-w; if (nx >= 0 && ny >= 0 && nx < w && ny < h && str[ny][nx] == '#' && !vis[ny][nx]) { vis[ny][nx] = true; tcnt++; } } } if (tcnt*2 == cnt) { std::cout << "YES" << std::endl; return 0; } } } } std::cout << "NO" << std::endl; return 0; }