結果

問題 No.179 塗り分け
ユーザー mencotton
提出日時 2020-11-02 16:08:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 79 ms / 3,000 ms
コード長 1,939 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 75,588 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-23 15:21:44
合計ジャッジ時間 2,913 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++)cin >> s[i];

    {
        int count = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (s[i][j] == '#')count++;
            }
        }
        if (count == 0 || count % 2 == 1) {
            cout << "NO" << endl;
            return 0;
        }
    }

    bool ret = false;
    for (int x = 0; x < 50; x++) {
        for (int y = 0; y < 50; y++) {
            if (x == 0 && y == 0)continue;

            vector<string> now = s;
            bool ok = true;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (now[i][j] == '#') {
                        if (i + x < h && j + y < w && now[i + x][j + y] == '#') {
                            now[i + x][j + y] = '.';
                        } else {
                            ok = false;
                        }
                    }
                }
            }
            if (ok)ret = true;
        }
    }

    for (int i = 0; i < h; i++) reverse(s[i].begin(), s[i].end());

    for (int x = 0; x < 50; x++) {
        for (int y = 0; y < 50; y++) {
            if (x == 0 && y == 0)continue;

            vector<string> now = s;
            bool ok = true;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (now[i][j] == '#') {
                        if (i + x < h && j + y < w && now[i + x][j + y] == '#') {
                            now[i + x][j + y] = '.';
                        } else {
                            ok = false;
                        }
                    }
                }
            }
            if (ok)ret = true;
        }
    }

    cout << (ret ? "YES" : "NO") << endl;
    return 0;
}
0