結果

問題 No.179 塗り分け
ユーザー ser
提出日時 2018-01-04 09:56:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 19 ms / 3,000 ms
コード長 1,343 bytes
コンパイル時間 740 ms
コンパイル使用メモリ 77,772 KB
最終ジャッジ日時 2025-01-05 06:59:19
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |     scanf("%d%d", &h, &w);
      |     ~~~~~^~~~~~~~~~~~~~~~
main.cpp:47:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |             scanf("%c", &field[x + y*w]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <climits>
#include <tuple>

using namespace std;

int h, w;

bool check(const vector<char>& field, int mx, int my) {
    bool red = false;

    vector<char> f = field;
    for(int y=0; y<h; y++) {
        for(int x=0; x<w; x++) {
            if(f[x+y*w] == '#') {
                f[x+y*w] = 'R';
                red = true;
                
                int bx = x+mx;
                int by = y+my;
                if(!(0<=bx && bx<w && 0<=by && by<h)) return false;
                if(f[bx+by*w] == '#') {
                    f[bx+by*w] = 'B';
                } else {
                    return false;
                }
            }
        }
    }

    return red;
}

int main() {
    scanf("%d%d", &h, &w);
    getchar();

    auto field = vector<char>(w*h);
    for(int y=0; y<h; y++) {
        for(int x=0; x<w; x++) {
            scanf("%c", &field[x + y*w]);
        }
        getchar();
    }
    
    for(int mx=-w+1; mx<w; mx++) {
        for(int my=-h+1; my<h; my++) {
            if(mx==0 && my==0) continue;
            if(check(field, mx, my)) {
                printf("YES\n");
                return 0;
            }
        }
    }

    printf("NO\n");        
    
    return 0;
}
0