Submission #495779


Source Code Expand

#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <iomanip>

#define rep(i,n) for(int i = 0; i < static_cast<int>(n); ++i)
using namespace std;


using R = double;
constexpr R EPS = 1E-11;
R hungarian(const vector<vector<R>>& a){//{{{
    int n = a.size(), p, q;
    vector<R> fx(n, numeric_limits<R>::max()), fy(n, 0);
    vector<int> x(n, -1), y(n, -1);
    rep(i, n) rep(j, n) fx[i] = max(fx[i], a[i][j]);
    for(int i = 0; i < n; ){
        vector<int> t(n, -1), s(n+1, i);
        for(p=q=0; p <= q && x[i] < 0; ++p)
            for(int k = s[p], j=0; j < n && x[i] < 0; ++j)
                if(abs(fx[k] + fy[j] - a[k][j]) < EPS && t[j] < 0){
                    s[++q] = y[j], t[j] = k;
                    if(s[q] < 0) for(p = j; p >= 0; j = p)
                        y[j] = k = t[j], p = x[k], x[k] = j;
                }
        if(x[i] < 0){
            R d = numeric_limits<R>::max();
            rep(k, q+1) rep(j, n) if(t[j] < 0)
                d = min(d, fx[s[k]] + fy[j] - a[s[k]][j]);
            rep(j, n) fy[j] += (t[j] < 0 ? 0 : d);
            rep(k, q+1) fx[s[k]] -= d;
        }else ++i;
    }
    R res = 0;
    rep(i, n) res += a[i][x[i]];
    return res;
}//}}}

int main(){//{{{
    int n;
    cin >> n;
    int x, y; cin >> x >> y;
    vector<int> sx(n), sy(n), tx(n), ty(n);
    rep(i, n) cin >> sx[i] >> sy[i] >> tx[i] >> ty[i];
    vector<vector<R>> g(n, vector<R>(n));
    rep(i, n) rep(j, n) g[i][j] = -hypot(sx[i]-tx[j], sy[i]-ty[j]);
    R res = -hungarian(g);
    rep(i, n) res += hypot(sx[i] - tx[i], sy[i] - ty[i]);
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}//}}}
// vim:set foldmethod=marker commentstring=//%s:

Submission Info

Submission Time
Task H - Laser Cutter
User MiSawa
Language C++11 (GCC 4.8.1)
Score 100
Code Size 1769 Byte
Status AC
Exec Time 180 ms
Memory 1568 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 55
Set Name Test Cases
All 00_sample_00, 00_sample_01, 00_sample_02, 11-small_random-00, 11-small_random-01, 11-small_random-02, 11-small_random-03, 11-small_random-04, 11-small_random-05, 11-small_random-06, 11-small_random-07, 11-small_random-08, 11-small_random-09, 11-small_random-10, 11-small_random-11, 11-small_random-12, 11-small_random-13, 11-small_random-14, 11-small_random-15, 11-small_random-16, 11-small_random-17, 11-small_random-18, 11-small_random-19, 12-large_random-00, 12-large_random-01, 12-large_random-02, 12-large_random-03, 12-large_random-04, 12-large_random-05, 12-large_random-06, 12-large_random-07, 12-large_random-08, 12-large_random-09, 12-large_random-10, 12-large_random-11, 12-large_random-12, 12-large_random-13, 12-large_random-14, 12-large_random-15, 12-large_random-16, 12-large_random-17, 12-large_random-18, 12-large_random-19, 13-maximum_random-00, 13-maximum_random-01, 13-maximum_random-02, 13-maximum_random-03, 13-maximum_random-04, 13-maximum_random-05, 13-maximum_random-06, 13-maximum_random-07, 13-maximum_random-08, 13-maximum_random-09, 80_minimum_00, 80_minimum_01
Case Name Status Exec Time Memory
00_sample_00 AC 24 ms 912 KB
00_sample_01 AC 24 ms 928 KB
00_sample_02 AC 24 ms 800 KB
11-small_random-00 AC 33 ms 716 KB
11-small_random-01 AC 25 ms 800 KB
11-small_random-02 AC 26 ms 804 KB
11-small_random-03 AC 26 ms 804 KB
11-small_random-04 AC 24 ms 800 KB
11-small_random-05 AC 29 ms 916 KB
11-small_random-06 AC 24 ms 804 KB
11-small_random-07 AC 25 ms 800 KB
11-small_random-08 AC 26 ms 920 KB
11-small_random-09 AC 24 ms 732 KB
11-small_random-10 AC 25 ms 800 KB
11-small_random-11 AC 27 ms 912 KB
11-small_random-12 AC 26 ms 736 KB
11-small_random-13 AC 25 ms 832 KB
11-small_random-14 AC 26 ms 920 KB
11-small_random-15 AC 27 ms 772 KB
11-small_random-16 AC 26 ms 808 KB
11-small_random-17 AC 27 ms 804 KB
11-small_random-18 AC 26 ms 932 KB
11-small_random-19 AC 26 ms 924 KB
12-large_random-00 AC 78 ms 1176 KB
12-large_random-01 AC 180 ms 1444 KB
12-large_random-02 AC 157 ms 1444 KB
12-large_random-03 AC 138 ms 1320 KB
12-large_random-04 AC 136 ms 1308 KB
12-large_random-05 AC 114 ms 1432 KB
12-large_random-06 AC 119 ms 1192 KB
12-large_random-07 AC 75 ms 1208 KB
12-large_random-08 AC 91 ms 1188 KB
12-large_random-09 AC 69 ms 1180 KB
12-large_random-10 AC 57 ms 1180 KB
12-large_random-11 AC 65 ms 1064 KB
12-large_random-12 AC 61 ms 1184 KB
12-large_random-13 AC 60 ms 1052 KB
12-large_random-14 AC 48 ms 1056 KB
12-large_random-15 AC 41 ms 996 KB
12-large_random-16 AC 39 ms 1056 KB
12-large_random-17 AC 85 ms 1316 KB
12-large_random-18 AC 139 ms 1304 KB
12-large_random-19 AC 81 ms 1428 KB
13-maximum_random-00 AC 136 ms 1556 KB
13-maximum_random-01 AC 173 ms 1440 KB
13-maximum_random-02 AC 139 ms 1448 KB
13-maximum_random-03 AC 135 ms 1564 KB
13-maximum_random-04 AC 87 ms 1440 KB
13-maximum_random-05 AC 116 ms 1568 KB
13-maximum_random-06 AC 82 ms 1564 KB
13-maximum_random-07 AC 96 ms 1440 KB
13-maximum_random-08 AC 148 ms 1432 KB
13-maximum_random-09 AC 119 ms 1440 KB
80_minimum_00 AC 27 ms 920 KB
80_minimum_01 AC 27 ms 796 KB