Submission #2170151


Source Code Expand

using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using SB = System.Text.StringBuilder;
using Number = System.Int64;
using System.Numerics;
using static System.Math;
namespace Program {
    public class Solver {
        //Random rnd = new Random(0);
        public void Solve() {
            var n = ri;
            var P = Enumerate(n, x => new long[] { ri, ri, ri });
            var es = new List<KeyValuePair<int, double>>();
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++)
                {
                    var dx = P[i][0] - P[j][0];
                    var dy = P[i][1] - P[j][1];
                    es.Add(new KeyValuePair<int, double>(i * n + j, Math.Sqrt(dx * dx + dy * dy)));
                }
            es.Sort((l, r) => l.Value.CompareTo(r.Value));
            var cost = new double[1 << n];
            for (int i = 1; i < 1 << n; i++)
            {
                var set = new DisjointSet(n);
                foreach (var e in es)
                {
                    var u = e.Key / n;
                    var v = e.Key % n;
                    if ((i >> u & 1) == 1 && (i >> v & 1) == 1 && set.Unite(u, v)) cost[i] -= e.Value;
                }
                var cnt = 0;
                for (int j = 0; j < n; j++)
                    if ((i >> j & 1) == 1) { cost[i] += P[j][2]; cnt++; }
                cost[i] /= cnt;
            }
            var dp = new double[1 << n];
            for (int i = 0; i < 1 << n; i++)
            {
                dp[i] = cost[i];
                for (int s = i; s > 0; s = (s - 1) & i)
                    dp[i] = Max(dp[i], Min(dp[s], dp[s ^ i]));
            }

            Console.WriteLine("{0:0.000000000000}", dp.Last());

        }
        const long INF = 1L << 60;
        //static int[] dx = { -1, 0, 1, 0 };
        //static int[] dy = { 0, 1, 0, -1 };

        int ri { get { return sc.Integer(); } }
        long rl { get { return sc.Long(); } }
        double rd { get { return sc.Double(); } }
        string rs { get { return sc.Scan(); } }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

        static T[] Enumerate<T>(int n, Func<int, T> f) {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f(i);
            return a;
        }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}

#region main
static class Ex {
    static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
        return string.Join(st, ie);
    }
    static public void Main() {
        Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
        var solver = new Program.Solver();
        try
        {
            solver.Solve();
            Console.Out.Flush();
        }
        catch { }
    }
}
#endregion
#region Ex
namespace Program.IO {
    using System.IO;
    using System.Text;
    using System.Globalization;

    public class Printer: StreamWriter {
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    }

    public class StreamScanner {
        public StreamScanner(Stream stream) { str = stream; }

        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }

        private byte read() {
            if (isEof) return 0;
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }

        public char Char() {
            byte b = 0;
            do b = read(); while ((b < 33 || 126 < b) && !isEof);
            return (char)b;
        }
        public string Scan() {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine() {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
        public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
        public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
}

#endregion
#region DisjointSet
public class DisjointSet {
    int[] par;
    byte[] rank;
    public DisjointSet(int n) {
        par = new int[n];
        for (int i = 0; i < n; i++)
            par[i] = -1;
        rank = new byte[n];
    }
    public int this[int id] {
        get {
            if ((par[id] < 0)) return id;
            return par[id] = this[par[id]];
        }
    }
    public bool Unite(int x, int y) {
        x = this[x]; y = this[y];
        if (x == y) return false;
        if (rank[x] < rank[y]) { var z = x; x = y; y = z; }
        par[x] += par[y];
        par[y] = x;
        if (rank[x] == rank[y])
            rank[x]++;
        return true;
    }
    public int Size(int x) { return -par[this[x]]; }
    public bool IsUnited(int x, int y) { return this[x] == this[y]; }

}
#endregion

Submission Info

Submission Time
Task E - Water Distribution
User camypaper
Language C# (Mono 4.6.2.0)
Score 1000
Code Size 5907 Byte
Status AC
Exec Time 289 ms
Memory 18000 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 280 ms 16080 KB
001.txt AC 282 ms 15952 KB
002.txt AC 278 ms 15952 KB
003.txt AC 277 ms 18000 KB
004.txt AC 289 ms 13904 KB
005.txt AC 267 ms 15952 KB
006.txt AC 284 ms 15952 KB
007.txt AC 274 ms 13904 KB
008.txt AC 278 ms 13904 KB
009.txt AC 281 ms 15952 KB
010.txt AC 281 ms 15952 KB
011.txt AC 278 ms 13904 KB
012.txt AC 283 ms 15952 KB
013.txt AC 272 ms 15952 KB
014.txt AC 280 ms 15952 KB
015.txt AC 286 ms 13904 KB
016.txt AC 269 ms 15952 KB
017.txt AC 280 ms 15952 KB
018.txt AC 280 ms 15952 KB
019.txt AC 273 ms 18000 KB
020.txt AC 272 ms 15952 KB
021.txt AC 279 ms 15952 KB
022.txt AC 271 ms 15952 KB
023.txt AC 273 ms 15952 KB
024.txt AC 268 ms 15952 KB
025.txt AC 270 ms 17716 KB
026.txt AC 274 ms 15952 KB
027.txt AC 265 ms 15952 KB
028.txt AC 277 ms 15952 KB
029.txt AC 276 ms 15952 KB
030.txt AC 276 ms 15952 KB
031.txt AC 277 ms 13904 KB
032.txt AC 281 ms 18000 KB
033.txt AC 277 ms 15952 KB
034.txt AC 282 ms 15952 KB
035.txt AC 282 ms 13904 KB
036.txt AC 288 ms 13904 KB
037.txt AC 286 ms 15952 KB
038.txt AC 289 ms 13904 KB
039.txt AC 281 ms 15952 KB
040.txt AC 25 ms 11348 KB
041.txt AC 29 ms 13780 KB
042.txt AC 29 ms 9544 KB
043.txt AC 30 ms 11592 KB
example0.txt AC 29 ms 11592 KB
example1.txt AC 269 ms 15952 KB