답안 #106853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
106853 2019-04-20T18:36:05 Z someone_aa 구경하기 (JOI13_watching) C++17
0 / 100
544 ms 16928 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 2100;
int n, p, q;
set<int>st;
vector<int>v;
int dp[maxn][maxn];

bool check(int x) {
    for(int i=0;i<=v.size();i++) {
        for(int j=0;j<=v.size();j++) {
            dp[i][j] = 10000000;
        }
    }
    dp[0][0] = 0;

    int result = INT_MAX;
    for(int i=1;i<=v.size();i++) {
        //cout<<i<<":\n";
        for(int j=0;j<=q;j++) {
            for(int d=i;d>=1;d--) {
                if(v[i-1] - v[d-1] < x) {
                    dp[i][j] = min(dp[i][j], dp[d-1][j]+1);

                    if(j-1>=0) {
                        dp[i][j] = min(dp[i][j], dp[d-1][j-1]);
                    }

                }

                if(v[i-1] - v[d-1] < 2*x && j>=1) {
                    dp[i][j] = min(dp[i][j], dp[d-1][j-1]);
                }
            }

            //cout<<j<<": "<<dp[i][j]<<"\n";
            if(i == v.size()) {
                result = min(result, dp[i][j]);
            }
        }
    }
    return result <= p;
}

int main() {
    cin>>n>>p>>q;

    int x;
    for(int i=1;i<=n;i++) {
        cin>>x;
        st.insert(x);
    }

    for(int i:st) {
        v.pb(i);
    }
    q = min(q, int(v.size()));

    ll l = 0LL, r = 1LL * 1e9;
    ll result = LLONG_MAX;
    while(l < r) {
        ll mid = (l + r) / 2;

        if(check(mid)) {
            result = min(result, mid);
            r = mid - 1;
        }
        else {
            l = mid + 1;
        }
    }
    cout<<result<<"\n";
    return 0;
}

Compilation message

watching.cpp: In function 'bool check(int)':
watching.cpp:13:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<=v.size();i++) {
                 ~^~~~~~~~~~
watching.cpp:14:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<=v.size();j++) {
                     ~^~~~~~~~~~
watching.cpp:21:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<=v.size();i++) {
                 ~^~~~~~~~~~
watching.cpp:40:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(i == v.size()) {
                ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 768 KB Output is correct
2 Incorrect 3 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 544 ms 16928 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -