QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#30526#2457. Cheese, If You Pleasesinbad#WA 1ms3856kbC++176.1kb2022-04-29 20:45:152022-04-29 20:45:16

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-29 20:45:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3856kb
  • [2022-04-29 20:45:15]
  • 提交

answer

#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 T, class Cmp>
ostream& operator <<(ostream& out, const multiset<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...);
}

template <class T> auto vect(const T& v, int n) { return vector<T>(n, v); }
template <class T, class... D> auto vect(const T& v, int n, D... m) {
  return vector<decltype(vect(v, m...))>(n, vect(v, m...));
}

using int64 = long long;
using int128 = __int128_t;
using ii = pair<int, int>;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
// mt19937 mrand(random_device{}());
// int rnd(int x) { return mrand() % x; }
mt19937_64 mrand(random_device{}());
int64 rnd(int64 x) { return mrand() % x; }
int lg2(int64 x) { return sizeof(int64) * 8 - 1 - __builtin_clzll(x); }
template <class T> void out(const vector<T>& a) { for (int i = 0; i < SZ(a); ++i) cout << a[i] << " \n"[i + 1 == SZ(a)]; }
template <class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template <class T> void dedup(vector<T>& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }
void add_mod(int& x, int y) { x += y; if (x >= MOD) x -= MOD; }
void sub_mod(int& x, int y) { x += MOD - y; if (x >= MOD) x -= MOD; }

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

// max D=CX
// s.t. Ax<=B
//
// DCCC
// BAAA
// BAAA
// BAAA
template<size_t M, size_t N>
struct Simplex {
  const double EPS = 1e-10;

  double a[M][N];
  int id[M + N];
  int m, n;

  void pivot(int u, int v) {
    swap(id[n + u], id[v]);
    double t = a[u][v];
    a[u][v] = 1;
    for (int j = 0; j <= n; ++j) a[u][j] /= t;
    for (int i = 0; i <= m; ++i) {
      if (i != u && a[i][v]) {
        t = a[i][v];
        a[i][v] = 0; // note, it's different from gauss.
        for (int j = 0; j <= n; ++j) a[i][j] -= a[u][j] * t;
      }
    }
  }

  Simplex(int m, int n): m(m), n(n) {
    for (int j = 1; j <= n; ++j) id[j] = j;
  }

  // make B>=0
  bool init() {
    bool need = 0;
    for (int i = 1; i <= m; ++i) if (a[i][0] < 0) need = 1;
    if (!need) return true;

    while (true) {
      int u = 0, v = 0;
      for (int i = 1; i <= m; ++i) {
        if (a[i][0] < -EPS && (!u || rnd(2))) u = i;
        // if (a[i][0] < -EPS) { u = i; break; }
      }
      if (!u) break;
      for (int j = 1; j <= n; ++j) {
        if (a[u][j] < -EPS && (!v || rnd(2))) v = j;
        // if (a[u][j] < -EPS) { v = j; break; }
      }
      if (!v) {
        cout << "Infeasible" << '\n';
        return false;
      }
      pivot(u, v);
    }
    return true;
  }

  bool solve() {
    if (!init()) return false;

    while (true) {
      int u = 0, v = 0;
      // Bland rule: pick the smallest index
      for (int j = 1; j <= n && !v; ++j) {
        if (a[0][j] > EPS) v = j;
      }
      if (!v) break;
      double mi;
      bool first = true;
      for (int i = 1; i <= m; ++i) {
        if (a[i][v] > EPS && (first || a[i][0] / a[i][v] < mi)) {
          mi = a[i][0] / a[i][v];
          first = false;
          u = i;
        }
      }
      if (!u) {
        cout << "Unbounded" << endl;
        return false;
      }
      pivot(u, v);
    }
    return true;
  }

  vector<double> answer() {
    vector<double> x(n + 1);
    for (int i = 1; i <= m; ++i) x[id[n + i]] = a[i][0];
    return x;
  }
};

int main() {
  int m, n;
  cin >> m >> n;
  const int M = 50 + 1;
  const int N = 50 + 1;
  Simplex<M, N> lp(m, n);
  for (int i = 1; i <= m; ++i) cin >> lp.a[i][0];
  for (int j = 1; j <= n; ++j) {
    for (int i = 1; i <= m; ++i) {
      cin >> lp.a[i][j];
      lp.a[i][j] /= 100;
    }
    cin >> lp.a[0][j];
  }

  lp.solve();
  double ret = -lp.a[0][0];
  cout << ret << '\n';

  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3816kb

input:

4 4
100 0 123 456
10.0 20.0 30.0 40.0 2.56
40.0 0.0 25.0 35.0 3.84
40.0 30.0 20.0 10.0 1.23
33.0 0.0 34.0 33.0 4.23

output:

1281.82

result:

ok single line: '1281.82'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3856kb

input:

4 4
0 0 0 0
10.0 20.0 30.0 40.0 2.56
40.0 0.0 25.0 35.0 3.84
40.0 30.0 20.0 10.0 1.23
33.0 0.0 34.0 33.0 4.23

output:

-0.00

result:

wrong answer 1st lines differ - expected: '0.00', found: '-0.00'