Submission #15449321


Source Code Expand

Copy
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n), c(n), X, Y;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> c[i];
    X.push_back(x[i]);
    Y.push_back(y[i]);
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  Y.erase(unique(Y.begin(), Y.end()), Y.end());

  int lenX = X.size(), lenY = Y.size();
  int len = lenX + lenY;
  vector<int> v(n);
  vector<int64> ret(n + 1, 1LL << 60);
  for (int k = 0; k < (1 << len); ++k) {
    int cnt = __builtin_popcount(k);
    if (cnt > n) continue;
    for (int j = 0; j < n; ++j) v[j] = min(abs(x[j]), abs(y[j]));
    for (int i = 0; i < lenX; ++i) {
      if (k & (1 << i)) {
        for (int j = 0; j < n; ++j) {
          v[j] = min(v[j], abs(x[j] - X[i]));
        }
      }
    }
    for (int i = 0; i < lenY; ++i) {
      if (k & (1 << (lenX + i))) {
        for (int j = 0; j < n; ++j) {
          v[j] = min(v[j], abs(y[j] - Y[i]));
        }
      }
    }
    int64 sum = 0;
    for (int j = 0; j < n; ++j) sum += 1LL * v[j] * c[j];
    ret[cnt] = min(ret[cnt], sum);
  }
  for (int i = 0; i <= n; ++i) {
    cout << ret[i] << endl;
  }
  return 0;
}

Submission Info

Submission Time
Task E - M's Solution
User cuiaoxiang
Language C++ (Clang 10.0.0)
Score 0
Code Size 3676 Byte
Status WA
Exec Time 3308 ms
Memory 3136 KB

Compile Error

./Main.cpp:77:11: warning: unused variable 'INF' [-Wunused-const-variable]
const int INF = 1 << 29;
          ^
./Main.cpp:78:11: warning: unused variable 'MOD' [-Wunused-const-variable]
const int MOD = 1e9 + 7;
          ^
2 warnings generated.

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status AC
AC × 6
WA × 1
TLE × 9
Set Name Test Cases
Sample
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-corner-01.txt, 01-corner-02.txt, 01-corner-03.txt, 01-corner-04.txt, 01-corner-05.txt, 02-random-01.txt, 02-random-02.txt, 02-random-03.txt, 02-random-04.txt, 03-random-quarter-01.txt, 03-random-quarter-02.txt, 03-random-quarter-03.txt, 03-random-quarter-04.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 13 ms 2964 KB
00-sample-02.txt AC 2 ms 3132 KB
00-sample-03.txt AC 4 ms 3040 KB
01-corner-01.txt AC 19 ms 3136 KB
01-corner-02.txt WA 2 ms 2992 KB
01-corner-03.txt TLE 3308 ms 2712 KB
01-corner-04.txt AC 7 ms 3048 KB
01-corner-05.txt AC 2 ms 2960 KB
02-random-01.txt TLE 3308 ms 2812 KB
02-random-02.txt TLE 3308 ms 2892 KB
02-random-03.txt TLE 3308 ms 2856 KB
02-random-04.txt TLE 3308 ms 2952 KB
03-random-quarter-01.txt TLE 3308 ms 2836 KB
03-random-quarter-02.txt TLE 3308 ms 2864 KB
03-random-quarter-03.txt TLE 3308 ms 2768 KB
03-random-quarter-04.txt TLE 3308 ms 2836 KB