Submission #23316679


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, vector<ll>, greater<>> PQR;
struct edge {ll to;ll id;edge(ll t,ll i):to(t),id(i){}};
typedef vector<vector<ll> > Graph;
typedef vector<vector<edge> > WGraph;
#define rep(i, n) for(ll i = 0; (i) < ll(n); (i)++)
#define all(v) (v).begin(), (v).end()
#define pb emplace_back
#define V vector
#define uniquify(vec) (vec).erase(std::unique((vec).begin(), (vec).end()), (vec).end())
constexpr ll MOD1 = 1e9 + 7;
constexpr ll MOD9 =  998244353;
constexpr ll INF = MOD1*MOD1+1;
ll mod(ll n, ll m){if(n >= 0) {return n % m;} else return (n%m + m)%m;}
ll div_ceil(ll a, ll b){return (a + b - 1) / b;}
template<typename T> T pw(T x,ll n) {T ret=1;while(n>0){if(n&1)ret=ret*x;x=x*x;n>>=1;}return ret;}
template<typename T> void rsort(vector<T> &v) {sort(all(v), greater<T>());}
template<typename T> bool chmax(T &a,const T& b) {if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,const T& b) {if(a>b){a=b;return true;}return false;}
template<typename T> void fin(const T &a) {cout << a << '\n';exit(0);}
template<typename T, typename S> pair<T, S> mp(const T &a, const S &b){return make_pair(a, b);}
template<typename T, typename S>
std::ostream &operator<<(std::ostream& os, const pair<T, S> &p){
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T>
std::ostream &operator<<(std::ostream& os, const vector<T> &v){
    int n = v.size();
    os << "[";
    for(int i = 0; i < n; i++){
        if(i == n - 1) os << v[i];
        else os << v[i] << ", ";
    }
    os << "]";
    return os;
}
template <typename T, typename S>
std::ostream &operator<<(std::ostream& os, const map<T, S> &mp){
    for(auto iter = mp.begin(); iter != mp.end(); iter++){
        os << "(" << iter->first << ", " << iter->second << ")" << " ";
    }
    return os;
}
template <typename T>
std::ostream &operator<<(std::ostream& os, const set<T> &s){
    os << "{";
    for(auto c : s) os << c << " ";
    os << "}";
    return os;
}
//#define LOCAL
#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dump(x) true
#endif

using mint = modint1000000007;
//using mint = modint998244353;


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);

    ll R_, B_, x_, y_;
    __int128 R, B, x, y; cin >> R_ >> B_ >> x_ >> y_;
    R = R_;
    B = B_;
    x = x_;
    y = y_;
    if(x == 1 || y == 1){
        cout << ll(min(R, B)) << '\n';
        exit(0);
    }
    if(B * x < R){
        cout << ll(B) << '\n';
        exit(0);
    } else if(R * y < B){
        cout << ll(R) << '\n';
        exit(0);
    }
    __int128 ub = (R * (y - 1) + B * (x - 1)) / (x * y - 1);
    __int128 l = (ub * y - B + y - 1 - 1) / (y - 1);
    __int128 u = (R - ub) / (x - 1);
    if(ub <= 0){
        fin(0);
    }
    if(u >= l && ub * y / (y - 1) >= l){
        cout << ll(ub) << '\n';
    } else {
        cout << ll(ub) - 1 << '\n';
    }

    return 0;
}

Submission Info

Submission Time
Task B - 花束
User Focus_Sash
Language C++ (GCC 9.2.1)
Score 100
Code Size 3302 Byte
Status AC
Exec Time 10 ms
Memory 3676 KiB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 60
Set Name Test Cases
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt
Case Name Status Exec Time Memory
01.txt AC 10 ms 3640 KiB
02.txt AC 5 ms 3512 KiB
03.txt AC 2 ms 3640 KiB
04.txt AC 3 ms 3524 KiB
05.txt AC 2 ms 3620 KiB
06.txt AC 3 ms 3596 KiB
07.txt AC 2 ms 3596 KiB
08.txt AC 2 ms 3584 KiB
09.txt AC 2 ms 3636 KiB
10.txt AC 3 ms 3516 KiB
11.txt AC 2 ms 3584 KiB
12.txt AC 2 ms 3588 KiB
13.txt AC 2 ms 3640 KiB
14.txt AC 4 ms 3580 KiB
15.txt AC 2 ms 3636 KiB
16.txt AC 2 ms 3640 KiB
17.txt AC 2 ms 3580 KiB
18.txt AC 2 ms 3580 KiB
19.txt AC 2 ms 3580 KiB
20.txt AC 2 ms 3640 KiB
21.txt AC 2 ms 3512 KiB
22.txt AC 2 ms 3568 KiB
23.txt AC 2 ms 3516 KiB
24.txt AC 2 ms 3568 KiB
25.txt AC 2 ms 3640 KiB
26.txt AC 2 ms 3636 KiB
27.txt AC 2 ms 3640 KiB
28.txt AC 2 ms 3668 KiB
29.txt AC 2 ms 3628 KiB
30.txt AC 2 ms 3524 KiB
31.txt AC 2 ms 3640 KiB
32.txt AC 2 ms 3524 KiB
33.txt AC 2 ms 3640 KiB
34.txt AC 2 ms 3640 KiB
35.txt AC 3 ms 3672 KiB
36.txt AC 2 ms 3660 KiB
37.txt AC 2 ms 3600 KiB
38.txt AC 2 ms 3636 KiB
39.txt AC 2 ms 3580 KiB
40.txt AC 3 ms 3640 KiB
41.txt AC 2 ms 3676 KiB
42.txt AC 3 ms 3620 KiB
43.txt AC 2 ms 3664 KiB
44.txt AC 2 ms 3640 KiB
45.txt AC 2 ms 3636 KiB
46.txt AC 3 ms 3468 KiB
47.txt AC 7 ms 3640 KiB
48.txt AC 2 ms 3528 KiB
49.txt AC 2 ms 3524 KiB
50.txt AC 6 ms 3580 KiB
51.txt AC 2 ms 3664 KiB
52.txt AC 2 ms 3636 KiB
53.txt AC 2 ms 3524 KiB
54.txt AC 3 ms 3636 KiB
55.txt AC 2 ms 3580 KiB
56.txt AC 2 ms 3584 KiB
57.txt AC 2 ms 3640 KiB
58.txt AC 3 ms 3588 KiB
59.txt AC 2 ms 3468 KiB
60.txt AC 2 ms 3564 KiB