結果
| 問題 | No.3583 二部マッチング最適化 |
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2026-07-03 23:47:34 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 6,000 ms |
| コード長 | 1,992 bytes |
| 記録 | |
| コンパイル時間 | 4,118 ms |
| コンパイル使用メモリ | 368,092 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2026-07-03 23:48:32 |
| 合計ジャッジ時間 | 4,877 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 44 |
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
template <class S>
struct value_compression : vector<S> {
bool built = false;
using VS = vector<S>;
using VS::VS;
value_compression(vector<S> v) : vector<S>(move(v)) {}
void build() {
sort(this->begin(), this->end());
this->erase(unique(this->begin(), this->end()), this->end());
built = true;
}
template <class T>
void convert(T first, T last) {
assert(built);
for (; first != last; ++first) *first = (*this)(*first);
}
int operator()(S x) {
assert(built);
return lower_bound(this->begin(), this->end(), x) - this->begin();
}
void clear() {
this->clear();
built = false;
}
};
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, l;
cin >> n >> m >> l;
value_compression<int> vc;
VI a(n), b(m);
rep(i, n) cin >> a[i], vc.emplace_back(a[i]);
rep(i, m) cin >> b[i], vc.emplace_back(b[i]);
vc.build();
int sz = vc.size(), s = sz, t = s + 1;
mcf_graph<int, int> g(t + 1);
rep(i, sz - 1) {
g.add_edge(i, i + 1, l, vc[i+1] - vc[i]);
g.add_edge(i + 1, i, l, vc[i+1] - vc[i]);
}
for (int x : a) g.add_edge(s, vc(x), 1, 0);
for (int x : b) g.add_edge(vc(x), t, 1, 0);
auto [flow, cost] = g.flow(s, t, l);
assert(flow == l);
cout << cost << '\n';
}
Kude