結果
問題 | No.1122 Plane Tickets |
ユーザー | satashun |
提出日時 | 2020-07-22 21:47:34 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 3,581 bytes |
コンパイル時間 | 2,381 ms |
コンパイル使用メモリ | 203,740 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 17:34:31 |
合計ジャッジ時間 | 3,390 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 2 ms
6,944 KB |
testcase_23 | AC | 1 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 1 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 1 ms
6,944 KB |
testcase_34 | AC | 2 ms
6,940 KB |
testcase_35 | AC | 2 ms
6,940 KB |
testcase_36 | AC | 1 ms
6,940 KB |
testcase_37 | AC | 2 ms
6,940 KB |
testcase_38 | AC | 2 ms
6,940 KB |
testcase_39 | AC | 2 ms
6,944 KB |
testcase_40 | AC | 2 ms
6,940 KB |
testcase_41 | AC | 2 ms
6,940 KB |
testcase_42 | AC | 2 ms
6,940 KB |
testcase_43 | AC | 2 ms
6,940 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,940 KB |
testcase_48 | AC | 2 ms
6,944 KB |
testcase_49 | AC | 2 ms
6,944 KB |
testcase_50 | AC | 2 ms
6,940 KB |
testcase_51 | AC | 2 ms
6,940 KB |
testcase_52 | AC | 2 ms
6,944 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,944 KB |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:123:20: warning: narrowing conversion of 'a' from 'll' {aka 'long long int'} to 'long double' [-Wnarrowing] 123 | double B[5] = {a, b, c, d, e}; | ^ main.cpp:123:23: warning: narrowing conversion of 'b' from 'll' {aka 'long long int'} to 'long double' [-Wnarrowing] 123 | double B[5] = {a, b, c, d, e}; | ^ main.cpp:123:26: warning: narrowing conversion of 'c' from 'll' {aka 'long long int'} to 'long double' [-Wnarrowing] 123 | double B[5] = {a, b, c, d, e}; | ^ main.cpp:123:29: warning: narrowing conversion of 'd' from 'll' {aka 'long long int'} to 'long double' [-Wnarrowing] 123 | double B[5] = {a, b, c, d, e}; | ^ main.cpp:123:32: warning: narrowing conversion of 'e' from 'll' {aka 'long long int'} to 'long double' [-Wnarrowing] 123 | double B[5] = {a, b, c, d, e}; | ^
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define ALL(c) (c).begin(), (c).end() constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "{"; rep(i, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif #define FOR(i, c) for (typeof(c.begin()) i = c.begin(); i != c.end(); ++i) #define REP(i, n) for (int i = 0; i < n; ++i) #define fst first #define snd second #define double long double const double EPS = 1e-6, INF = 1. / 0.; double simplexMethodPD(double c[], int n, double b[], int m, double A[]) { double T[m + 1][n + m + 1]; memset(T, 0, sizeof(T)); REP(j, m) { REP(i, n) T[j][i] = A[j * n + i]; T[j][n + j] = 1; T[j][n + m] = b[j]; } REP(i, n) T[m][i] = c[i]; while (1) { int p = 0, q = 0; REP(i, n + m) if (T[m][i] <= T[m][p]) p = i; REP(j, m) if (T[j][n + m] <= T[q][n + m]) q = j; double t = min(T[m][p], T[q][n + m]); if (t >= -EPS) return -T[m][n + m]; // optimal if (t < T[q][n + m]) { // tight on c -> primal update REP(j, m) if (T[j][p] >= EPS) if (T[j][p] * (T[q][n + m] - t) >= T[q][p] * (T[j][n + m] - t)) q = j; if (T[q][p] <= EPS) return INF; // primal infeasible } else { // tight on b -> dual update REP(i, n + m + 1) T[q][i] *= -1; REP(i, n + m) if (T[q][i] >= EPS) if (T[q][i] * (T[m][p] - t) >= T[q][p] * (T[m][i] - t)) p = i; if (T[q][p] <= EPS) return -INF; // dual infeasible } REP(i, m + n + 1) if (i != p) T[q][i] /= T[q][p]; T[q][p] = 1; // pivot(q,p) REP(j, m + 1) if (j != q) { double alpha = T[j][p]; REP(i, n + m + 1) T[j][i] -= T[q][i] * alpha; } } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll a, b, c, d, e; cin >> a >> b >> c >> d >> e; double A[25]; rep(i, 5) rep(j, 5) { A[i * 5 + j] = 0.0; int w = i - j; if (w < 0) w += 5; if (w <= 2) A[i * 5 + j] = 1.0; } double B[5] = {a, b, c, d, e}; double C[5] = {-1, -1, -1, -1, -1}; auto res = simplexMethodPD(C, 5, B, 5, A); cout << ll(-res) << endl; return 0; }