답안 #1041219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041219 2024-08-01T18:03:13 Z SoulKnight Self Study (JOI22_ho_t2) C++17
0 / 100
1000 ms 4944 KB
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ln '\n'

const int N = 3e5 + 5;
const ll INF = 5e18 + 5;

ll n, m, a[N], b[N];
inline ll ceil(ll x, ll y) {return (x + y - 1) / y;}
ll cnt(ll go_lesson, ll i, ll tar){
    return (m - go_lesson) - max(0LL, ceil(tar - a[i] * go_lesson, b[i]));
}

void solve(){
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    // ll l = 7, r = 7, ans = 0;
    ll l = 0, r = INF, ans = 0;
    while (l <= r){
        ll tar = (l + r) / 2;
        ll free, need; free = need = 0;

        for (int i = 0; i < n; i++){
            if (b[i] >= a[i]) {
                free += m;
                need += ceil(tar, b[i]);
            } else {
                // maybe don't blindly go to lessons
                ll lf = 0, rt = m, glit = 0;
                while (glit++ < 40){
                    ll tl = (2 * lf + rt) / 3;
                    ll tr = (lf + 2 * rt) / 3;
                    if (cnt(tl, i, tar) > cnt(tr, i, tar)) rt = tr;
                    else lf = tl;
                }

                ll best = lf;
                for (ll j = max(0LL, lf - 100); j <= min(m, lf + 100); j++){
                    if (cnt(j, i, tar) > cnt(best, i, tar)) best = j;
                }

                free += m - best;
                need += max(0LL, ceil(tar - a[i] * best, b[i]));
            }
            // cout << need << ' ' << free << ln;
        }
        if (need <= free) {ans = tar; l = tar + 1;}
        else r = tar - 1;
    }
    cout << ans << ln;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    // int TT; cin >> TT;
    // while (TT--) {solve();}

    solve();

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 372 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 52 ms 348 KB Output is correct
11 Execution timed out 1033 ms 4944 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 35 ms 2792 KB Output is correct
10 Correct 23 ms 1828 KB Output is correct
11 Correct 18 ms 1644 KB Output is correct
12 Correct 15 ms 1372 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Incorrect 1 ms 348 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 372 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 52 ms 348 KB Output is correct
11 Execution timed out 1033 ms 4944 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 35 ms 2792 KB Output is correct
10 Correct 23 ms 1828 KB Output is correct
11 Correct 18 ms 1644 KB Output is correct
12 Correct 15 ms 1372 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Incorrect 1 ms 348 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 372 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 52 ms 348 KB Output is correct
11 Execution timed out 1033 ms 4944 KB Time limit exceeded
12 Halted 0 ms 0 KB -