結果
問題 | No.1122 Plane Tickets |
ユーザー | startcpp |
提出日時 | 2020-07-22 22:53:33 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 3,375 bytes |
コンパイル時間 | 1,215 ms |
コンパイル使用メモリ | 82,316 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 17:35:58 |
合計ジャッジ時間 | 2,280 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 3 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,944 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 2 ms
6,940 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,944 KB |
testcase_33 | AC | 2 ms
6,944 KB |
testcase_34 | AC | 2 ms
6,944 KB |
testcase_35 | AC | 2 ms
6,944 KB |
testcase_36 | AC | 2 ms
6,940 KB |
testcase_37 | AC | 2 ms
6,944 KB |
testcase_38 | AC | 2 ms
6,944 KB |
testcase_39 | AC | 2 ms
6,944 KB |
testcase_40 | AC | 2 ms
6,940 KB |
testcase_41 | AC | 2 ms
6,944 KB |
testcase_42 | AC | 2 ms
6,944 KB |
testcase_43 | AC | 2 ms
6,944 KB |
testcase_44 | AC | 2 ms
6,940 KB |
testcase_45 | AC | 2 ms
6,944 KB |
testcase_46 | AC | 2 ms
6,944 KB |
testcase_47 | AC | 2 ms
6,944 KB |
testcase_48 | AC | 2 ms
6,940 KB |
testcase_49 | AC | 2 ms
6,944 KB |
testcase_50 | AC | 2 ms
6,944 KB |
testcase_51 | AC | 2 ms
6,940 KB |
testcase_52 | AC | 2 ms
6,940 KB |
testcase_53 | AC | 2 ms
6,940 KB |
testcase_54 | AC | 2 ms
6,940 KB |
testcase_55 | AC | 2 ms
6,940 KB |
testcase_56 | AC | 2 ms
6,940 KB |
ソースコード
//http://www.prefield.com/algorithm/math/two_stage_simplex.html #include <iostream> #include <cstdio> #include <cmath> #include <vector> using namespace std; typedef vector<double> Array; typedef vector<Array> Matrix; const double EPS = 1e-8; enum { OPTIMAL, UNBOUNDED, NOSOLUTION, UNKNOWN }; struct two_stage_simplex { int N, M, st; Matrix a; vector<int> s; two_stage_simplex(const Matrix &A, const Array &b, const Array &c) : N(A.size()), M(A[0].size()), a(N+2, Array(M+N+1)), s(N+2), st(UNKNOWN) { for (int j = 0; j < M; ++j) a[N+1][j] = c[j]; // make simplex table for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) a[i+1][j] = A[i][j]; for (int i = 0; i < N; ++i) a[i+1][M+N] = b[i]; // add helper table for (int i = 0; i < N; ++i) a[ 0 ][i+M] = 1; for (int i = 0; i < N; ++i) a[i+1][i+M] = 1; for (int i = 0; i < N; ++i) s[i+1] = i+M; for (int i = 1; i <= N; ++i) for (int j = 0; j <= N+M; ++j) a[0][j] += a[i][j]; st = solve(); } int status() const { return st; } double solution() const { return -a[0][M]; } double solution(Array &x) const { x.resize(M, 0); for (int i = 0; i < N; ++i) x[s[i+1]] = a[i+1].back(); return -a[0][M]; } int solve() { M += N; N += 1; solve_sub(); // solve stage one if (solution() > EPS) return NOSOLUTION; N -= 1; M -= N; swap(a[0], a.back()); a.pop_back(); // modify table for (int i = 0; i <= N; ++i) { swap(a[i][M], a[i].back()); a[i].resize(M+1); } return solve_sub(); // solve stage two } int solve_sub() { int p, q; while (1) { //print(); for (q = 0; q <= M && a[0][q] >= -EPS; ++q); for (p = 0; p <= N && a[p][q] <= EPS; ++p); if (q >= M || p > N) break; for (int i = p+1; i <= N; ++i) // bland's care for cyclation if (a[i][q] > EPS) if (a[i][M]/a[i][q] < a[p][M]/a[p][q] || (a[i][M]/a[i][q] == a[p][M]/a[p][q] && s[i] < s[q])) p = i; pivot(p, q); } if (q >= M) return OPTIMAL; else return UNBOUNDED; } void pivot(int p, int q) { for (int j = 0; j <= N; ++j) for (int k = M; k >= 0; --k) if (j != p && k != q) a[j][k] -= a[p][k]*a[j][q]/a[p][q]; for (int j = 0; j <= N; ++j) if (j != p) a[j][q] = 0; for (int k = 0; k <= M; ++k) if (k != q) a[p][k] = a[p][k]/a[p][q]; a[p][q] = 1.0; s[p] = q; } }; int main() { /*for (int n, m; cin >> n >> m; ) { Array c(n+m), b(m); for (int i = 0; i < n; ++i) cin >> c[i], c[i] *= -1; Matrix A(m, Array(n+m)); for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) cin >> A[i][j]; A[i][n+i] = 1; cin >> b[i]; } two_stage_simplex tss(A, b, c); double ans = -tss.solution(); printf("Nasa can spend %.0f taka.\n", ans + 0.5 - EPS); }*/ //整数計画ソルバーが欲しい(これは実数で計画しているからWAだと思う) Array c(5), b(5); for (int i = 0; i < 5; i++) { c[i] = 1; c[i] *= -1; } Matrix A(5, Array(10)); for (int i = 0; i < 5; i++) { for (int j = 0; j < 3; j++) { A[i][(i + j) % 5] = 1; } A[i][5 + i] = 1; } cin >> b[2] >> b[3] >> b[4] >> b[0] >> b[1]; two_stage_simplex tss(A, b, c); double ans = -tss.solution(); printf("%lld\n", (long long)(ans + 1e-9)); return 0; }