結果

問題 No.179 塗り分け
ユーザー AnchorBluesAnchorBlues
提出日時 2023-03-04 20:19:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,624 bytes
コンパイル時間 1,951 ms
コンパイル使用メモリ 183,976 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 04:42:25
合計ジャッジ時間 9,366 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;

const ll INF = 1LL << 60;

template <class T>
void chmax(T& a, T b) {
    if (b > a) a = b;
}
template <class T>
void chmin(T& a, T b) {
    if (b < a) a = b;
}

template <typename T, typename S>
std::ostream& operator<<(std::ostream& os, const pair<T, S>& x) noexcept {
    return os << "(" << x.first << ", " << x.second << ")";
}

template <typename T>
void print_vector(vector<T> a) {
    cout << '[';
    for (int i = 0; i < a.size(); i++) {
        cout << a[i];
        if (i != a.size() - 1) {
            cout << ", ";
        }
    }
    cout << ']' << endl;
}

template <typename T>
vector<T> s2v(set<T>& s) {
    vector<T> vec;
    for (auto& v : s) {
        vec.push_back(v);
    }
    return vec;
}

bool is_ok(int i0, int j0, vector<vector<char>>& Mat) {
    ll H = Mat.size();
    ll W = Mat[0].size();
    set<pll> reds, blues;
    for (int i = H - 1; i >= 0; i--) {
        for (int j = W - 1; j >= 0; j--) {
            if (Mat[i][j] == '#') {
                if (i >= i0 && j >= j0) {
                    if (blues.count({i, j})) {
                        reds.insert({i, j});
                    } else {
                        blues.insert({i - i0, j - j0});
                    }
                } else {
                    reds.insert({i, j});
                }
            }
        }
    }
    if (reds.size() != blues.size()) {
        return false;
    }
    auto reds_vec = s2v(reds);
    auto blues_vec = s2v(blues);
    ll N = reds.size();
    sort(reds_vec.begin(), reds_vec.end());
    sort(blues_vec.begin(), blues_vec.end());
    for (int i = 0; i < N; i++) {
        if (reds_vec[i].first != blues_vec[i].first) return false;
        if (reds_vec[i].second != blues_vec[i].second) return false;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll H, W;
    cin >> H >> W;
    vector<vector<char>> Mat(H, vector<char>(W, 0));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> Mat[i][j];
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i == 0 && j == 0) continue;
            if (is_ok(i, j, Mat)) {
                std::cout << "YES"
                          << "\n";
                return 0;
            }
        }
    }
    std::cout << "NO"
              << "\n";
    return 0;
}
0