Submission #22134422


Source Code Expand

Copy
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

template <typename Tp>
inline void read(Tp &x) {
    x = 0;
    bool f = true; char ch = getchar();
    for ( ; ch < '0' || ch > '9'; ch = getchar()) f ^= ch == '-';
    for ( ; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + (ch ^ 48);
    x = f ? x : -x;
}

const int N = 15;
const double inf = 1e18;

int a[N + 5], x[N + 5], y[N + 5];
double dis[N + 5][N + 5], f[1 << N];

int main() {
    int n;
    read(n);
    for (int i = 1; i <= n; ++i)
        read(x[i]), read(y[i]), read(a[i]);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            dis[i][j] = sqrt(1LL * (x[i] - x[j]) * (x[i] - x[j]) + 1LL * (y[i] - y[j]) * (y[i] - y[j]));
    for (int i = 1; i < (1 << n); ++i) f[i] = inf;
    for (int i = 1; i <= n; ++i) f[1 << (i - 1)] = 0;
    for (int i = 1; i < (1 << n); ++i) {
        for (int j = 0; j < n; ++j) {
            if (!(i & (1 << j))) continue;
            for (int k = 0; k < n; ++k) {
                if (i & (1 << k)) continue;
                f[i | (1 << k)] = std::min(f[i | (1 << k)], f[i] + dis[j + 1][k + 1]);
            }
        }
    }
    for (int i = 1; i < (1 << n); ++i) {
        f[i] = -f[i];
        int cnt = 0;
        for (int j = 0; j < n; ++j)
            if (i & (1 << j)) {
                f[i] += a[j + 1];
                ++cnt;
            }
        f[i] = std::max(0.0, f[i] / cnt);
        for (int S = (i - 1) & i; S; S = (S - 1) & i)
            f[i] = std::max(f[i], std::min(f[S], f[i ^ S]));
    }
    printf("%.12lf\n", f[(1 << n) - 1]);
    return 0;
}

Submission Info

Submission Time
Task E - Water Distribution
User vjudge1
Language C++ (GCC 9.2.1)
Score 1000
Code Size 1619 Byte
Status AC
Exec Time 73 ms
Memory 4068 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 2
AC × 46
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 72 ms 3892 KB
001.txt AC 68 ms 3808 KB
002.txt AC 63 ms 3948 KB
003.txt AC 64 ms 3836 KB
004.txt AC 68 ms 3884 KB
005.txt AC 64 ms 4064 KB
006.txt AC 69 ms 3948 KB
007.txt AC 66 ms 3900 KB
008.txt AC 70 ms 3836 KB
009.txt AC 66 ms 3960 KB
010.txt AC 69 ms 3864 KB
011.txt AC 71 ms 3904 KB
012.txt AC 67 ms 3904 KB
013.txt AC 67 ms 3900 KB
014.txt AC 73 ms 3812 KB
015.txt AC 72 ms 3836 KB
016.txt AC 65 ms 3948 KB
017.txt AC 67 ms 3848 KB
018.txt AC 70 ms 3964 KB
019.txt AC 65 ms 3812 KB
020.txt AC 61 ms 4064 KB
021.txt AC 65 ms 3908 KB
022.txt AC 66 ms 3892 KB
023.txt AC 61 ms 3964 KB
024.txt AC 60 ms 3880 KB
025.txt AC 62 ms 3896 KB
026.txt AC 61 ms 3840 KB
027.txt AC 66 ms 3880 KB
028.txt AC 60 ms 3840 KB
029.txt AC 60 ms 3908 KB
030.txt AC 61 ms 4068 KB
031.txt AC 63 ms 3908 KB
032.txt AC 63 ms 3812 KB
033.txt AC 61 ms 3900 KB
034.txt AC 57 ms 3948 KB
035.txt AC 64 ms 3896 KB
036.txt AC 62 ms 4012 KB
037.txt AC 61 ms 3832 KB
038.txt AC 65 ms 3960 KB
039.txt AC 60 ms 3960 KB
040.txt AC 2 ms 3656 KB
041.txt AC 2 ms 3784 KB
042.txt AC 2 ms 3692 KB
043.txt AC 2 ms 3752 KB
example0.txt AC 2 ms 3584 KB
example1.txt AC 68 ms 3848 KB