結果

問題 No.2675 KUMA
ユーザー 👑 nu50218nu50218
提出日時 2024-05-19 09:25:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,137 bytes
コンパイル時間 1,093 ms
コンパイル使用メモリ 90,060 KB
実行使用メモリ 16,960 KB
最終ジャッジ日時 2024-05-19 09:25:27
合計ジャッジ時間 7,570 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
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 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <tuple>

using namespace std;

vector<pair<int, int>> get_observable_positions(int x, int y) {
    vector<pair<int, int>> positions;
    positions.emplace_back(x + 2, y - 1);
    positions.emplace_back(x + 2, y + 1);
    positions.emplace_back(x - 2, y - 1);
    positions.emplace_back(x - 2, y + 1);
    positions.emplace_back(x - 1, y - 2);
    positions.emplace_back(x + 1, y - 2);
    positions.emplace_back(x - 1, y + 2);
    positions.emplace_back(x + 1, y + 2);
    return positions;
}

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> umas(N);
    set<pair<int, int>> uma_positions;

    for (int i = 0; i < N; ++i) {
        cin >> umas[i].first >> umas[i].second;
        uma_positions.insert(umas[i]);
    }

    set<pair<int, int>> all_positions;

    for (const auto& uma : umas) {
        auto positions = get_observable_positions(uma.first, uma.second);
        for (const auto& pos : positions) {
            if (uma_positions.find(pos) == uma_positions.end()) {
                all_positions.insert(pos);
            }
        }
    }

    vector<pair<int, int>> kma_candidates(all_positions.begin(), all_positions.end());
    int min_kma_count = N;  // 最小値は最大でもN

    int candidate_size = kma_candidates.size();
    for (int bit = 1; bit < (1 << candidate_size); ++bit) {
        set<pair<int, int>> observed_positions;
        for (int i = 0; i < candidate_size; ++i) {
            if (bit & (1 << i)) {
                auto observable = get_observable_positions(kma_candidates[i].first, kma_candidates[i].second);
                observed_positions.insert(observable.begin(), observable.end());
            }
        }
        bool all_observed = true;
        for (const auto& uma : umas) {
            if (observed_positions.find(uma) == observed_positions.end()) {
                all_observed = false;
                break;
            }
        }
        if (all_observed) {
            min_kma_count = min(min_kma_count, __builtin_popcount(bit));
        }
    }

    cout << min_kma_count << endl;

    return 0;
}
0