結果

問題 No.2390 Udon Coupon (Hard)
ユーザー x.t.
提出日時 2023-07-21 23:07:29
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,692 bytes
コンパイル時間 1,817 ms
コンパイル使用メモリ 173,968 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-22 00:37:09
合計ジャッジ時間 3,224 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

// Problem: No.2386 Udon Coupon (Easy)No.2386 乌冬面优惠券 (简易)
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2386
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
#define x first
#define y second
ll ksm(ll n,ll p,int mod){
	int ans=1;
	while(p){
		if(p&1) ans=(ans*n)%mod;
		n=(n*n)%mod;p>>=1;
	}
	return ans;
}
ll inv(ll b,ll c=mod) {return ksm(b,c-2,c);}
class Num{
public:
	ll num;
	Num(ll x) {num=(x%mod+mod)%mod;}
	Num operator+(Num p) {return Num(num+p.num);}
	Num operator-(Num p) {return Num(num-p.num);}
	Num operator*(Num p) {return Num(num*p.num);}
	Num operator/(Num p) {return Num(num*inv(p.num));}
	Num operator=(Num p) {this->num=p.num;return *this;}
	friend ll get(Num p) {return p.num;}
};
void solve() {
	ll n;
	cin>>n;
	vector<pair<ll,ll>> ve;
	for(int i=0;i<3;i++) {
		ll a,b;
		cin>>a>>b;
		ve.push_back({a,b});
	}
	sort(ve.begin(),ve.end());
	ll ans=0;
	while(n>=ve[0].x||n>=ve[1].x||n>=ve[2].x) {
		ll t0=ve[0].y/ve[0].x;
		ll t1=ve[1].y/ve[1].x;
		ll t2=ve[2].y/ve[2].x;
		ll mx=0;
		if(n>=ve[0].x) mx=max(mx,t0);
		if(n>=ve[1].x) mx=max(mx,t1);
		if(n>=ve[2].x) mx=max(mx,t2);
		if(mx==t0) {
			ans+=n/ve[0].x*ve[0].y;
			n%=ve[0].x;
		}
		else if(mx==t1) {
			ans+=n/ve[1].x*ve[1].y;
			n%=ve[1].x;
		}
		else if(mx==t2) {
			ans+=n/ve[2].x*ve[2].y;
			n%=ve[2].x;
		}
	}
	cout<<ans<<endl;
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T=1;
    //cin>>T;
    while(T--) {
    	solve();
    }
    return 0;
}
0