結果

問題 No.179 塗り分け
ユーザー ともきともき
提出日時 2015-10-12 00:40:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 3,000 ms
コード長 3,952 bytes
コンパイル時間 1,157 ms
コンパイル使用メモリ 133,024 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 20:44:44
合計ジャッジ時間 2,830 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cassert>

#include <unordered_set>
#include <unordered_map>
#include <random>
#include <thread>
#include <chrono>

using namespace std;

#define int long long
#define let const auto
#define var auto

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x) 
#endif

typedef complex<double> point;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    for(auto it = v.begin(); it != v.end(); ++it){
        if(it != v.begin()){
            os << ",";
        }
        os << *it;
    }
    return os << "}";
}
template<typename T>
void isort(std::vector<T>& v, std::function<bool(T,T)> comp=less<T>()){
    sort(v.begin(), v.end(), comp);
}
template<typename T>
std::vector<T> sort(std::vector<T> v, std::function<bool(T,T)> comp=less<T>()){
    isort(v);
    return v;
}
template<typename T1, typename T2>
std::vector<T2> rmap(const std::vector<T1>& v, std::function<T2(T1)> f){
    std::vector<T2> t; t.reserve(v.size());
    for(const auto& i: v) t.push_back(f(i));
    return t;
}
std::vector<std::string> split(std::string str, char delim){
    std::vector<std::string> res;
    size_t current = 0, found;
    while((found = str.find_first_of(delim, current)) != std::string::npos){
        res.push_back(std::string(str, current, found - current));
        current = found + 1;
    }
    res.push_back(std::string(str, current, str.size() - current));
    return res;
}
string join(const std::vector<string>& v, string delim){
    string ret = "";
    for(auto it = v.begin(); it != v.end(); ++it){
        if(it != v.begin()){
            ret += delim;
        }
        ret += *it;
    }
    return ret;
}

bool try_solve(const vector<vector<bool> >& field,
               int sy, int sx){
    int h = field.size();
    int w = field[0].size();
    set<pair<int,int>> is_red;

    int ix = (sx > 0) ? 0 : (w-1);
    int xd = (sx > 0) ? 1 : -1;
    int iy = (sy > 0) ? 0 : (h-1);
    int yd = (sy > 0) ? 1 : -1;
    for(int x=ix;0 <= x && x < w;x+=xd){
        for(int y=iy;0 <= y && y < h;y+=yd){
            if(field[y][x] &&
               is_red.find(make_pair(y,x)) == is_red.end()){
                int nx = x + sx;
                int ny = y + sy;
                if(nx < 0 || ny < 0 || nx >= w || ny >= h) return false;
                if(!field[ny][nx]) return false;
                is_red.insert(make_pair(ny,nx));
            }
        }
    }

    return true;
}

bool solve(const vector<vector<bool> >& field){
    int h = field.size();
    int w = field[0].size();
    for(int sy=-h;sy<=h;sy++){
        for(int sx=-w;sx<=w;sx++){
            if(sx == 0 && sy == 0) continue;
            if(try_solve(field,sy,sx)) return true;
        }
    }
    return false;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int h, w; cin >> h >> w;
    bool is_there_tile = false;
    vector<vector<bool>> field = [&]{
        vector<string> f(h);
        for(auto& s : f) cin >> s;
        return rmap<string, vector<bool>>(f, [&](string r){
                vector<bool> row(w, false);
                for(int i=0;i<r.length();i++){
                    row[i] = r[i] == '#';
                    is_there_tile |= (r[i] == '#');
                }
                return row;
            });
    }();

    cout << ((is_there_tile && solve(field)) ? "YES" : "NO") << endl;
    return 0;
}
0