結果
| 問題 |
No.1122 Plane Tickets
|
| コンテスト | |
| ユーザー |
satashun
|
| 提出日時 | 2020-07-22 21:47:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,000 ms |
| コード長 | 3,581 bytes |
| コンパイル時間 | 2,027 ms |
| コンパイル使用メモリ | 196,784 KB |
| 最終ジャッジ日時 | 2025-01-12 02:32:50 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 55 |
コンパイルメッセージ
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;
}
satashun