Блог пользователя f.verri

Автор f.verri, история, 12 месяцев назад, По-английски

Hello. I have been trying to solve this problem for a while now and I can't find the bug that's causing the WA, I know it's probably being caused by a stupid typo, but I can't find it at all. The code is failing on test case 2

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define iter(i, l, r) for (ll i = l; i < r; i++)

bool isPossible(ll day, ll n, ll p, ll l, ll t) {
    ll tasks = ceil(float(n) / 7.0);
    ll maxTasks = min(tasks, (n - day) * 2);

    return ((n - day) * l) + (maxTasks * t) >= p;
}

int main() {
    ll numberOfTestCases;
    cin >> numberOfTestCases;

    vector<ll> toShow;

    iter (_, 0, numberOfTestCases) {
        ll n, p, l, t;
        cin >> n >> p >> l >> t;

        ll start = 0;
        ll ender = n;
        while (ender - start > 1) {
            ll mid = (start + ender) / 2;

            if (isPossible(mid, n, p, l, t)) {
                start = mid;
            } else {
                ender = mid;
            }
        }

        toShow.push_back(start);
    }

    for (ll x : toShow) {
        cout << x << "\n";
    }

    return 0;
}
  • Проголосовать: нравится
  • -4
  • Проголосовать: не нравится

»
12 месяцев назад, # |
Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится
consider
2 100 50 50

your code outputs 0, it should output 1.

Edit : I got AC with your same code with C++ 17, C++ 20 gives WA, if u get rid of floor and ceil

and use (n + 6) / 7, then C++ 20 also gives AC with ur code 236404618

  • »
    »
    12 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Thank you so much. I would have never realized that. Do you think it's bad practice to use floating numbers like i did on the isPossible function? By the way, sorry for not linking the problem, i ended up forgotting