結果
| 問題 | No.640 76本のトロンボーン | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-01-27 03:05:10 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 3,842 bytes | 
| コンパイル時間 | 2,360 ms | 
| コンパイル使用メモリ | 213,152 KB | 
| 最終ジャッジ日時 | 2025-01-05 07:59:38 | 
| ジャッジサーバーID (参考情報) | judge1 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 4 WA * 11 | 
ソースコード
#include <bits/stdc++.h>
#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
vector<T> Vec(int n, T v)
{
    return vector<T>(n, v);
}
template <class... Args>
auto Vec(int n, Args... args)
{
    auto val = Vec(args...);
    return vector<decltype(val)>(n, move(val));
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}
template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}
constexpr ll MOD = (ll)1e9 + 7LL;
constexpr ld PI = static_cast<ld>(3.1415926535898);
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
struct Graph {
    Graph(const int n)
    {
        edge.resize(n);
    }
    void addEdge(const int from, const int to)
    {
        edge[from].push_back(to);
        edge[to].push_back(from);
    }
    vector<vector<int>> edge;
};
int N;
int ans;
int num;
void MaximumIndependentSet(const Graph& g, const vector<bool>& used, const int use, const int res)
{
    if (use + res <= ans) {
        return;
    }
    ans = max(ans, use);
    for (int i = 0; i < num; i++) {
        if (not used[i]) {
            vector<bool> tmp = used;
            int tmpres = res - 1;
            for (const int to : g.edge[i]) {
                if (not used[to]) {
                    tmpres--;
                    tmp[to] = true;
                }
            }
            MaximumIndependentSet(g, tmp, use + 1, tmpres);
        }
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    vector<bool> ok(4 * N, true);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            char c;
            cin >> c;
            if (c == '#') {
                if (i < N - 2) {
                    ok[j] = false;
                    ok[N + j] = false;
                } else if (i == N - 1) {
                    ok[N + j] = false;
                }
                if (j < N - 2) {
                    ok[2 * N + i] = false;
                    ok[2 * N + N + i] = false;
                } else if (i == N - 1) {
                    ok[2 * N + N + i] = false;
                }
            }
        }
    }
    map<int, int> mp;
    for (int i = 0; i < 4 * N; i++) {
        if (ok[i]) {
            mp[i] = num;
            num++;
        }
    }
    Graph g(num);
    for (int i = 0; i < 4 * N; i++) {
        if (not ok[i]) {
            continue;
        }
        vector<vector<bool>> tmp(N, vector<bool>(N, true));
        if (i < 2 * N) {
            for (int j = 0; j < N - 1; j++) {
                tmp[i / N + j][i % N] = false;
            }
        } else {
            for (int j = 0; j < N - 1; j++) {
                tmp[(i - 2 * N) % N][(i - 2 * N) / N + j] = false;
            }
        }
        for (int j = i + 1; j < 4 * N; j++) {
            if (not ok[j]) {
                continue;
            }
            if (j < 2 * N) {
                for (int k = 0; k < N - 1; k++) {
                    if (not tmp[j / N + k][j % N]) {
                        g.addEdge(mp[i], mp[j]);
                        break;
                    }
                }
            } else {
                for (int k = 0; k < N - 1; k++) {
                    if (tmp[(j - 2 * N) % N][(j - 2 * N) / N + k]) {
                        g.addEdge(mp[i], mp[j]);
                        break;
                    }
                }
            }
        }
    }
    vector<bool> used(num, false);
    MaximumIndependentSet(g, used, 0, num);
    cout << ans << endl;
    return 0;
}
            
            
            
        