結果

問題 No.453 製薬会社
ユーザー chaemonchaemon
提出日時 2016-12-04 01:46:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,067 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 101,492 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-27 19:35:59
合計ジャッジ時間 1,555 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
#ifdef __MINGW32__
typedef rn rn;
#else
typedef long double rn;
//typedef double rn;
#endif

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

typedef vector<rn> vec;
typedef vector<vec> matrix;

const rn 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 vec &b, const vec &c)
		: N(A.size()), M(A[0].size()), a(N+2, vec(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; }
	rn solution() const { return -a[0][M]; }
	rn solution(vec &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);
		}
		cout<<"second stage"<<endl;
		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; ) {
		vec c(n+m), b(m);
		for (int i = 0; i < n; ++i)
			cin >> c[i], c[i] *= -1;
		matrix A(m, vec(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);
		rn ans = -tss.solution() * m;
		printf("Nasa can spend %.0f taka.\n", ans + 0.5 - EPS);
	}
}
*/

int main(){
	int C,D;
	cin>>C>>D;
	matrix A(2,vec(2,0.0));
	A[0][0] = 3.0/4.0;
	A[0][1] = 2.0/7.0;
	A[1][0] = 1.0/4.0;
	A[1][1] = 5.0/7.0;
	vec b(2);
	b[0] = C;
	b[1] = D;
	vec c(2);
	c[0] = -1000.0;
	c[1] = -2000.0;
	two_stage_simplex tss(A,b,c);
	rn ans = -tss.solution();
	printf("%.10Lf\n",ans);
	return 0;
}
0