제출 #1181853

#제출 시각아이디문제언어결과실행 시간메모리
1181853SmuggingSpunSelf Study (JOI22_ho_t2)C++20
100 / 100
123 ms2788 KiB
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
typedef long long ll;
template<class T>void minimize(T& a, T b){
    if(a > b){
        a = b;
    }
}
const int INF = 2e9;
int n, m;
namespace sub1{
    void solve(){
        vector<int>a(n);
        for(int& x : a){
            cin >> x;
        }
        int ans = INF;
        for(int i = 0; i < n; i++){
            int x;
            cin >> x;
            minimize(ans, max(x, a[i]));
        }
        cout << ans;
    }
}
namespace sub2345{
    const int lim = 3e5 + 5;
    int a[lim], b[lim];
    void solve(){
        for(int i = 1; i <= n; i++){
            cin >> a[i];
        }
        for(int i = 1; i <= n; i++){
            cin >> b[i];
        }
        ll low = 1, high = 1e18, ans = 0, max_cnt = 1LL * n * m;
        while(low <= high){
            ll mid = (low + high) >> 1LL, cnt = 0;
            for(int i = 1; i <= n && cnt <= max_cnt; i++){
                if(a[i] > b[i]){
                    int coef = min(ll(m), (mid - 1) / a[i] + 1);
                    cnt += coef;
                    ll remain = mid - 1LL * coef * a[i];
                    if(remain > 0){
                        cnt += (remain - 1) / b[i] + 1;
                    }
                }
                else{
                    cnt += (mid - 1) / b[i] + 1;
                }
            }
            if(cnt > max_cnt){
                high = mid - 1;
            }
            else{
                low = (ans = mid) + 1;
            }
        }
        cout << ans;
    }
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
    cin >> n >> m;
    if(m == 1){
        sub1::solve();
    }
    else{
        sub2345::solve();
    }
}

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

Main.cpp: In function 'int main()':
Main.cpp:66:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...