結果

問題 No.179 塗り分け
ユーザー 鴨志田卓
提出日時 2023-08-09 20:32:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 3,000 ms
コード長 1,404 bytes
コンパイル時間 1,656 ms
コンパイル使用メモリ 193,264 KB
最終ジャッジ日時 2025-02-16 00:26:25
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
const int N = 55;

int n, m;
char s[N][N], t[N][N];

bool check(int v1, int v2) {
    memcpy(t, s, sizeof s);
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
            if(t[i][j] == '#') {
                t[i][j] = '.';
                if(i + v1 > n || j + v2 > m || t[i + v1][j + v2] == '.')
                    return false;
                t[i + v1][j + v2] = '.';
            }
    return true;
}

bool check2(int v1, int v2) {
    memcpy(t, s, sizeof s);
    for(int i = 1; i <= n; i ++)
        for(int j = m; j >= 1; j --)
            if(t[i][j] == '#') {
                t[i][j] = '.';
                if(i + v1 > n || j - v2 <= 0 || t[i + v1][j - v2] == '.')
                    return false;
                t[i + v1][j - v2] = '.';
            }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> m;
    int cnt = 0;
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++) {
            cin >> s[i][j];
            cnt += (s[i][j] == '#');
        }
    
    if(!cnt) {
        cout << "NO\n";
        return 0;
    }
    
    for(int i = 0; i <= n; i ++)
        for(int j = 0; j <= m; j ++)
            if(check(i, j) || check2(i, j)) {
                cout << "YES\n";
                return 0;
            }
    cout << "NO\n";
}
0