Submission #1036342


Source Code Expand

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

const int maxn = 15;
int xs[maxn], ys[maxn], a[maxn];

int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d%d%d", xs + i, ys + i, a + i);
  }
  return 1;
}

long long sum[1 << maxn];
ld dp[1 << maxn];

ld ans[1 << maxn];

ld dist[maxn][maxn];

void solve() {
  sum[0] = 0;
  dp[0] = 0;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int dx = xs[i] - xs[j], dy = ys[i] - ys[j];
      dist[i][j] = sqrt((ld) dx * dx + (ld) dy * dy);
    }
  }

  ans[0] = inf;
  for (int mask = 1; mask < (1 << n); ++mask) {
    int id = __builtin_ctz(mask);
    sum[mask] = sum[mask ^ (1 << id)] + a[id];

    if (mask == (1 << id)) {
      dp[mask] = 0;
    } else {
      dp[mask] = 1e18;
      for (int i = 0; i < n; ++i) {
        if (!((mask >> i) & 1)) {
          continue;
        }
        for (int j = 0; j < n; ++j) {
          if (i == j || !((mask >> j) & 1)) {
            continue;
          }
          dp[mask] = min(dp[mask], dp[mask ^ (1 << i)] + dist[i][j]);
        }
      }
    }

    ans[mask] = (sum[mask] - dp[mask]) / __builtin_popcount(mask);
    for (int x = mask; x; x = ((x - 1) & mask)) {
      ans[mask] = max(ans[mask], min(ans[x], ans[mask ^ x]));
    }
  }
  printf("%.18f\n", (double) ans[(1 << n) - 1]);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

Submission Info

Submission Time
Task E - Water Distribution
User XraY
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 2256 Byte
Status AC
Exec Time 151 ms
Memory 1536 KB

Compile Error

./Main.cpp: In function ‘int read()’:
./Main.cpp:46:43: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", xs + i, ys + i, a + i);
                                           ^

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 143 ms 1536 KB
001.txt AC 141 ms 1536 KB
002.txt AC 134 ms 1536 KB
003.txt AC 141 ms 1536 KB
004.txt AC 146 ms 1536 KB
005.txt AC 138 ms 1536 KB
006.txt AC 146 ms 1536 KB
007.txt AC 139 ms 1536 KB
008.txt AC 143 ms 1536 KB
009.txt AC 146 ms 1536 KB
010.txt AC 147 ms 1536 KB
011.txt AC 148 ms 1536 KB
012.txt AC 146 ms 1536 KB
013.txt AC 138 ms 1536 KB
014.txt AC 148 ms 1536 KB
015.txt AC 151 ms 1536 KB
016.txt AC 136 ms 1536 KB
017.txt AC 147 ms 1536 KB
018.txt AC 145 ms 1536 KB
019.txt AC 140 ms 1536 KB
020.txt AC 122 ms 1536 KB
021.txt AC 135 ms 1536 KB
022.txt AC 134 ms 1536 KB
023.txt AC 123 ms 1536 KB
024.txt AC 124 ms 1536 KB
025.txt AC 121 ms 1536 KB
026.txt AC 127 ms 1536 KB
027.txt AC 123 ms 1536 KB
028.txt AC 123 ms 1536 KB
029.txt AC 123 ms 1536 KB
030.txt AC 121 ms 1536 KB
031.txt AC 123 ms 1536 KB
032.txt AC 119 ms 1536 KB
033.txt AC 119 ms 1536 KB
034.txt AC 117 ms 1536 KB
035.txt AC 117 ms 1536 KB
036.txt AC 116 ms 1536 KB
037.txt AC 116 ms 1536 KB
038.txt AC 117 ms 1536 KB
039.txt AC 118 ms 1536 KB
040.txt AC 3 ms 256 KB
041.txt AC 3 ms 256 KB
042.txt AC 3 ms 256 KB
043.txt AC 3 ms 256 KB
example0.txt AC 3 ms 256 KB
example1.txt AC 130 ms 1536 KB