답안 #727740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727740 2023-04-21T08:42:49 Z sandry24 구경하기 (JOI13_watching) C++17
0 / 100
2 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second

const int maxn = 2005;
vi events;
int n, small, large;

bool possible(int w){
    vi small_range(n), large_range(n);
    int j = 0;
    for(int i = 0; i < n; i++){
        while(j < n && events[j] - events[i] < w)
            j++;
        small_range[i+1] = j;
        j--;
    }
    j = 0;
    for(int i = 0; i < n; i++){
        while(j < n && events[j] - events[i] < 2*w)
            j++;
        large_range[i+1] = j;
        j--;
    }
    vector<vi> dp(small+1, vi(large+1));
    //dp[i][j] = highest index you can cover with i small j big
    for(int i = 0; i <= small; i++){
        for(int j = 0; j <= large; j++){
            if(i > 0)
                dp[i][j] = max(dp[i][j], small_range[dp[i-1][j] + 1]);
            if(j > 0)
                dp[i][j] = max(dp[i][j], large_range[dp[i][j-1] + 1]);
        }
    }
    return (dp[small][large] >= n);
}

void solve(){
    cin >> n >> small >> large;
    if(small + large >= n){
        cout << 1 << '\n';
        return;
    }
    events = vi(n);
    for(int i = 0; i < n; i++){
        cin >> events[i];
    }
    sort(events.begin(), events.end());
    int current = 0;
    for(int add = 1e9; add > 0; add /= 2){
        while(!possible(current+add))
            current += add;
    }
    cout << current+1 << '\n';
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("test.out", "w", stdout);
    //ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -