結果

問題 No.3068 Speedrun (Hard)
ユーザー shobonvip
提出日時 2025-03-21 22:46:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,320 ms / 2,000 ms
コード長 2,065 bytes
コンパイル時間 4,321 ms
コンパイル使用メモリ 253,136 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2025-03-21 22:47:01
合計ジャッジ時間 28,095 ms
ジャッジサーバーID
(参考情報)
judge7 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
	author:  shobonvip
	created: 2025.03.21 22:09:45
**/

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	vector<int>a(4),b(4);
	rep(i,0,4)cin>>a[i];
	int n;cin>>n;
	rep(i,0,4)cin>>b[i];
	int t;cin>>t;
	int mode=0;
	if(b[0]>b[1]){
		swap(a[0],a[1]);
		swap(b[0],b[1]);
		mode|=1;
	}
	if(b[2]<b[3]){
		swap(b[2],b[3]);
		swap(a[2],a[3]);
		mode|=2;
	}

	vector<int> ans;
	rep(i,0,n+1){
		vector<int>memo;
		vector<int>xt;
		vector<int>yt;
		rep(x,0,a[0]+1){
			int y=i-x;
			if(!(0<=y&&y<=a[1]))continue;
			int g=x*b[0]+y*b[1];
			memo.push_back(g);
			xt.push_back(x);
			yt.push_back(y);
		}
		int p=0;
		rep(x,0,a[2]+1){
			int y=n-i-x;
			if(!(0<=y&&y<=a[3]))continue;
			int g=x*b[2]+y*b[3];
			while(p<(int)memo.size()&&g+memo[p]>t){
				p++;
			}
			if(p<(int)memo.size()&&g+memo[p]==t){
				ans={xt[p],yt[p],x,y};
				break;
			}
		}
	}


	if(mode&1)swap(ans[0],ans[1]);
	if(mode&2)swap(ans[2],ans[3]);
	cout<<ans[0]<<' '<<ans[1]<<' '<<ans[2]<<' '<<ans[3]<<endl;
}

0