結果

問題 No.1669 パズル作成
ユーザー t33ft33f
提出日時 2021-09-04 01:20:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,520 bytes
コンパイル時間 942 ms
コンパイル使用メモリ 86,220 KB
実行使用メモリ 5,416 KB
最終ジャッジ日時 2023-08-22 04:12:14
合計ジャッジ時間 4,610 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 101 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <set>
#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<vector<int> > adj(2*n);
    for (int i = 0; i < m; i++) {
        int r, c; cin >> r >> c;
        r--; c--; c += n;
        adj[r].push_back(c);
        adj[c].push_back(r);
    }
    vector<pair<int, int> > AB;
    struct DFS {
        int n;
        vector<bool> visited;
        vector<vector<int> > &adj;
        DFS(int n, vector<vector<int> > &adj) : n(n), visited(2*n, false), adj(adj) {}
        void dfs(int i, int &a, int &b) {
            visited[i] = true;
            if (i < n) a++; else b++;
            for (int j : adj[i]) if (!visited[j]) dfs(j, a, b);
        }
        pair<int, int> dfs(int i) {
            int a = 0, b = 0;
            dfs(i, a, b);
            return {a, b};
        }
    } dfs(n, adj);
    for (int i = 0; i < 2*n; i++) {
        if (!dfs.visited[i]) {
            auto [a, b] = dfs.dfs(i);
            AB.emplace_back(a, b);
        }
    }

    vector<int> bmin(n+1, n), bmax(n+1, 0);
    for (auto [a, b] : AB) {
        for (int i = 0; i <= n - a; i++) {
            bmin[i + a] = min(bmin[i + a], bmin[i] + b);
            bmax[i + a] = max(bmax[i + a], bmax[i] + b);
        }
    }
    int ans = n * n;
    for (int a = 0; a <= n; a++) {
        if (2 * a <= n)
            ans = min(ans, n * (n - a) - (n - 2 * a) * bmax[a]);
        else
            ans = min(ans, n * (n - a) - (n - 2 * a) * bmin[a]);
    }
    cout << ans - m << '\n';
}
0