結果

問題 No.179 塗り分け
ユーザー koya_bot2koya_bot2
提出日時 2020-04-21 13:53:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,725 bytes
コンパイル時間 886 ms
コンパイル使用メモリ 84,664 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-16 22:50:10
合計ジャッジ時間 5,625 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using vii = std::vector<std::pair<int,int>>;

template<class TupleT>
TupleT diff(TupleT l, TupleT r)
{
    return {std::get<0>(l) - std::get<0>(r), std::get<1>(l) - std::get<1>(r)};
}

template<class TupleT>
TupleT add(TupleT l, TupleT r)
{
    return {std::get<0>(l) + std::get<0>(r), std::get<1>(l) + std::get<1>(r)};
}

bool f2(vii blacks, size_t firstI, size_t firstJ)
{
    std::pair d = diff(blacks[firstJ], blacks[firstI]);
    std::vector<bool> used(blacks.size(), false);
    used[firstI] = true;
    used[firstJ] = true;

    for (size_t i = 0; i < blacks.size(); i++)
    {
        if (used[i]) continue;
        std::pair expected = add(blacks[i], d);
        auto it = std::lower_bound(begin(blacks), end(blacks), expected);
        
        if (it != end(blacks) && *it == expected)
        {
            int j = it - begin(blacks);
            used[j] = true;
        }
        else
        {
            return false;
        }
        
    }
    
    return true;
}

bool f(const vii &blacks)
{
    size_t B = blacks.size();
    if (B % 2 != 0) return false;

    bool ret = false;
    for (size_t i = 0; i < B; i++)
    {
        for (size_t j = i+1; j < B; j++)
        {
            ret = ret || f2(blacks, i, j);
        }
    }
    return ret;
}

int main()
{
    int H, W;
    std::cin >> H >> W;
    vii blacks;
    for (int h = 0; h < H; h++)
    {
        std::string S;
        std::cin >> S;
        for (int w = 0; w < W; w++)
        {
            if (S[w] == '#') blacks.emplace_back(h, w);
        }
    }

    bool ans = f(blacks);
    const char *anss = ans ? "YES" : "NO";
    std::cout << anss << std::endl;
}
0