답안 #956340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956340 2024-04-01T16:16:46 Z steveonalex 구경하기 (JOI13_watching) C++17
100 / 100
46 ms 31324 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return __lg(mask);}

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T& container, char separator = ' ', char finish = '\n'){
        for(auto item: container) cout << item << separator;
        cout << finish;
    }

template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const long N = 2007;

long n, a, b;
vector<long> x;
long dp[N][N];

bool check(long w){
    vector<long> nxt1(n+1), nxt2(n+1);
    for(long i = 0; i<n; ++i){
        if (x[i] + w > 1e9){
            nxt1[i] = nxt2[i] = n;
        }
        else{
            nxt1[i] = lower_bound(ALL(x), x[i] + w) - x.begin();
            nxt2[i] = lower_bound(ALL(x), x[i] + w*2) - x.begin();
        }
    }
    nxt1[n] = nxt2[n] = n;

    for(long i = 0; i<=a; ++i)
    for(long j = 0; j<=b; ++j) dp[i][j] = 0;
    for(long i = a; i>=0; --i)
    for(long j = b; j>=0; --j){
        if (i > 0) maximize(dp[i-1][j], nxt1[dp[i][j]]);
        if (j > 0) maximize(dp[i][j-1], nxt2[dp[i][j]]);
    }

    return (dp[0][0] >= n);
}

int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> a >> b;
    x.resize(n);
    for(long i = 0; i<n; ++i) cin >> x[i];
    sort(ALL(x));

    if (a + b >= n){
        cout << 1 << "\n";
        return 0;
    }

    long l = 1, r = 1e9;
    long s = a + b;
    r = (r + s - 1) / s;
    while(l < r){
        long mid = (l + r) >> 1;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }

    cout << l << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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 1 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 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 2648 KB Output is correct
8 Correct 8 ms 2704 KB Output is correct
9 Correct 9 ms 12892 KB Output is correct
10 Correct 18 ms 31324 KB Output is correct
11 Correct 9 ms 2652 KB Output is correct
12 Correct 46 ms 17056 KB Output is correct
13 Correct 5 ms 2396 KB Output is correct
14 Correct 5 ms 2632 KB Output is correct
15 Correct 5 ms 2396 KB Output is correct