제출 #1118135

#제출 시각아이디문제언어결과실행 시간메모리
1118135Zero_OPMeasures (CEOI22_measures)C++14
24 / 100
1566 ms5092 KiB
#include <bits/stdc++.h>

using namespace std;

void solve(vector<long long>& ar, int  D){
    if((int)ar.size() == 1){
        cout << 0 << ' ';
        return;
    }
    assert(is_sorted(ar.begin(), ar.end()));

    int N = (int)ar.size();

    long long l = 0, r = 1e18, ans = 0;
    while(l <= r){
        long long mid = l + r >> 1;
        bool ok = true;
        long long last = ar[0] - mid;
        for(int i = 1; i < N; ++i){
            if(last + D < ar[i] - mid){
                last = ar[i] - mid;
            } else if(last + D > ar[i] + mid){
                ok = false;
                break;
            } else{
                last += D;
            }
        }

        if(ok) ans = mid, r = mid - 1;
        else l = mid + 1;
    }

    if(ans & 1) cout << (ans >> 1) << ".5 ";
    else cout << (ans >> 1) << ' ';
}

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

#ifdef LOCAL
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
#endif // LOCAL

    int N, M;
    long long D;
    cin >> N >> M >> D;

    D <<= 1;

    vector<long long> ar;
    for(int i = 1; i <= N; ++i){
        long long x; cin >> x;
        ar.push_back(x << 1);
    }

    sort(ar.begin(), ar.end());

    for(int i = 1; i <= M; ++i){
        long long x; cin >> x;
        x <<= 1;
        ar.insert(lower_bound(ar.begin(), ar.end(), x), x);
        solve(ar, D);
    }

    return 0;
}

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

Main.cpp: In function 'void solve(std::vector<long long int>&, int)':
Main.cpp:16:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   16 |         long long mid = l + r >> 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...