제출 #585235

#제출 시각아이디문제언어결과실행 시간메모리
585235rgnerdplayerSelf Study (JOI22_ho_t2)C++17
100 / 100
229 ms9052 KiB
#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    auto solve = [&]() {
        int n, m;
        cin >> n >> m;

        vector<int> a(n), b(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            cin >> b[i];
            a[i] = max(a[i], b[i]);
        }

        i64 lo = 0, hi = 2e18;

        while (lo < hi) {
            i64 md = lo + hi + 1 >> 1;
            i64 cnt = 0;
            bool ok = true;
            
            for (int i = 0; i < n; i++) {
                if (md <= 1LL * m * a[i]) {
                    cnt += (md + a[i] - 1) / a[i];
                } else {
                    cnt += m + (md - 1LL * a[i] * m + b[i] - 1) / b[i];
                }
                if (cnt > 1LL * n * m) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                lo = md;
            } else {
                hi = md - 1;
            }
        }

        cout << lo << '\n';
    };
    
    solve();
    
    return 0;
}
 

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In lambda function:
Main.cpp:30:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |             i64 md = lo + hi + 1 >> 1;
      |                      ~~~~~~~~^~~
#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...