제출 #1269901

#제출 시각아이디문제언어결과실행 시간메모리
1269901jovid쌍둥이 독수리 (GA7_twineagles)C++20
52 / 100
1 ms328 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>

const int INF = 1LL << 62;

int count(int x, int y, int z) {
    // cout << x << " " << y << " " << z << '\n';
    if (y <= 0) {
        return 0;
    }
    if (x >= y) {
        return 1;
    }
    if (x <= z) {
        return INF;
    }
    // lo 실패
    int lo = 0;
    // hi 성공
    int hi = 2000000000LL;
    while (lo + 1 < hi) {
        int mid = (lo + hi) / 2;
        bool success = ((y - mid * x + mid * z - z) <= 0);
        if (success) {
            hi = mid;
        } else {
            lo = mid;
        }
    }
    return hi;
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    int atk, xl, yl, xh, yh;
    cin >> atk >> xl >> yl >> xh >> yh;
    int ans = INF;
    for (int i = 0; i < 2; ++i) {
        // kill x
        int d1 = count(2 * atk, xl, xh);
        // cout << d1 << endl;
        // d1일 뒤에는 무조건 죽음 즉, d1일에는 xl<= 0;
        // (d1-1)일의 x의 체력
        int x_last_life = xl - (d1 - 1) * (2 * atk) + (d1 - 1) * xh;
        // cout << x_last_life << endl;
        int d2;
        if (x_last_life > atk) {
            // cout << "case 1" << endl;
            // 2마리 독수리가 합심해야 하는 경우
            d2 = count(2 * atk, yl + d1 * yh, yh);
        } else {
            long long y_post = yl + (d1 - 1) * yh - atk;  // 그날 밤 회복 전, 공격 직후 체력
            if (y_post <= 0) {
                d2 = 0;  // 그날 즉시 사망 → 추가 일수 0
            } else {
                d2 = count(2 * atk, y_post + yh, yh);  // 밤 회복 후 다음 날부터
            }
            // 1마리만 때려도 되는 경우
            // cout << "case 2" << endl;
            // d2 = count(2 * atk, yl - atk + d1 * yh, yh);
        }
        // cout << d1 << ' ' << d2 << endl;
        ans = min(ans, d1 + d2);
        swap(xl, yl);
        swap(xh, yh);
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...