結果

問題 No.179 塗り分け
ユーザー nenuonnenuon
提出日時 2017-03-02 23:42:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 3,000 ms
コード長 2,435 bytes
コンパイル時間 721 ms
コンパイル使用メモリ 79,700 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 20:53:12
合計ジャッジ時間 2,624 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 13 ms
4,380 KB
testcase_09 AC 14 ms
4,380 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 12 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 8 ms
4,376 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 25 ms
4,380 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 15 ms
4,376 KB
testcase_25 AC 8 ms
4,380 KB
testcase_26 AC 9 ms
4,376 KB
testcase_27 AC 13 ms
4,376 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 14 ms
4,376 KB
testcase_30 AC 11 ms
4,380 KB
testcase_31 AC 14 ms
4,380 KB
testcase_32 AC 10 ms
4,376 KB
testcase_33 AC 15 ms
4,376 KB
testcase_34 AC 9 ms
4,380 KB
testcase_35 AC 13 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,384 KB
testcase_42 AC 2 ms
4,384 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 3 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

//方針
//ヒント見ましたTT
//ある#に対して移動量を(di, dj)として移動先が#ならok
//移動前と後の#を調査済みとする
//次に調査していない#に対して同じ作業をしていき
//全て調査済みになったらYESそうでないならNO
//-100<=di,dj<=100,

int main(){
    int H, W;
    cin >> H >> W;
    //getlineの前にcinがある場合はcin.ignore()しないとだめ
    cin.ignore();

    //長方形board
    int n_sharp = 0;
    vector<string> board;
    FOR(i, 0, H){
        string s;
        getline(cin, s);
        FOR(i, 0, s.length()) if(s[i]=='#') n_sharp++;
        board.push_back(s);
    }

    //#が0or奇数個ならNO
    if(n_sharp==0 || n_sharp%2==1){
        cout << "NO" << endl;
        return 0;
    }

    bool YES = false;
    FOR(di, -H, H+1){
        FOR(dj, -W, W+1){
            //移動しないパターンはcontinue
            if(di == 0 && dj == 0) continue;

            //(di, dj)移動する時
            //調査したかどうか1ならした0ならしてない
            int isok[H][W];
            FOR(i, 0, H) FOR(j, 0, W) isok[i][j] = 0;

            //#を見ていく
            int check = 1;
            FOR(i, 0, H){
                FOR(j, 0, W){
                    //塗ってない#があったら移動先も塗る
                    if(isok[i][j]==0 && board[i][j]=='#'){
                        //移動先が範囲外ならbreak
                        if(i+di>=H || i+di<0 || j+dj>=W || j+dj<0){
                            check = 0;
                            break;
                          }
                        if(board[i+di][j+dj]=='.'){
                            check = 0;
                            break;
                        }
                        isok[i+di][j+dj] = 1;
                    }
                }
                if(!check) break;
            }
            if(check){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}
0