結果

問題 No.179 塗り分け
ユーザー nenuonnenuon
提出日時 2017-03-02 23:33:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,226 bytes
コンパイル時間 868 ms
コンパイル使用メモリ 79,468 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-07-26 16:35:21
合計ジャッジ時間 2,587 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 12 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 11 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,384 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 12 ms
4,380 KB
testcase_21 AC 12 ms
4,380 KB
testcase_22 AC 13 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 13 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 12 ms
4,380 KB
testcase_28 WA -
testcase_29 AC 12 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 12 ms
4,376 KB
testcase_32 WA -
testcase_33 AC 12 ms
4,380 KB
testcase_34 WA -
testcase_35 AC 12 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,384 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,384 KB
testcase_43 AC 1 ms
4,384 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,380 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
    vector<string> board;
    FOR(i, 0, H){
        string s;
        getline(cin, s);
        board.push_back(s);
    }

    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){
                    //範囲外ならbreak
                    if(i+di>=H || i+di<0 || j+dj>=W || j+dj<0){
                        check = 0;
                        break;
                    }
                    //塗ってない#があったら移動先も塗る
                    if(isok[i][j]==0 && board[i][j]=='#'){
                        if(isok[i+di][j+dj]==1 || 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