結果

問題 No.179 塗り分け
ユーザー no15_renne
提出日時 2015-04-06 00:22:27
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,864 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 78,964 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-02 13:26:01
合計ジャッジ時間 3,508 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 38 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

const int INF = 1e9;
const int MOD = 1e9+7;
int h, w;
bool check(int x, int y, vector<vi> g){
    REP(i, h){
        REP(j, w){
            if(g[i][j]){
                int dx = i + x, dy = j + y;
                if(dx < 0 || dy < 0 || dx >= h || dy >= w) return false;
                if(!g[dx][dy]) return false;
                g[i][j] = g[dx][dy] = 0;
            }
        }
    }
    return true;
}
bool check2(int x, int y, vector<vi> g){
    RREP(i, h){
        RREP(j, w){
            if(g[i][j]){
                int dx = i + x, dy = j + y;
                if(dx < 0 || dy < 0 || dx >= h || dy >= w) return false;
                if(!g[dx][dy]) return false;
                g[i][j] = g[dx][dy] = 0;
            }
        }
    }
    return true;
}
int main(void){
    cin >> h >> w;
    vector<vi> g(h, vi(w, 0));
    REP(i, h){
        REP(j, w){
            char c; cin >> c;
            if(c == '#') g[i][j] = 1;
        }
    }
    for(int i = -60; i < 60; i++){
        for(int j = -60; j < 60; j++){
            if(!i && !j) continue;
            if(check(i, j, g) || check2(i, j, g)){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
	cout << "NO" << endl;
	return 0;
}

0