답안 #110930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110930 2019-05-13T07:29:40 Z Mercenary 구경하기 (JOI13_watching) C++14
100 / 100
199 ms 16248 KB
#include<bits/stdc++.h>

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp 	make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,ll> ii;
const int maxn = 2005;

int n , q , p;

int a[maxn];

int dp[maxn][maxn];

bool chk(int w){
    dp[0][0] = 0;
    int ii = 1 , jj = 1;
    for(int i = 1 ; i <= n ; ++i){
        while(a[i] - a[ii] + 1 > w)++ii;
        while(a[i] - a[jj] + 1 > 2 * w)++jj;
//        cout << ii << " " << jj << " " << i << endl;
        for(int j = 0 ; j <= i && j <= p ; ++j){
            if(j == 0)dp[i][j] = dp[jj - 1][j] + 1;
            else dp[i][j] = min(dp[jj - 1][j] + 1 , dp[ii - 1][j - 1]),dp[i][j] = min(dp[i][j] , dp[i][j - 1]);
        }
    }
//    cout << w << " " << dp[n][min(p,n)] << endl;
    return dp[n][min(p,n)] <= q;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> p >> q;
    int l = 1 , h = 1e9;
    for(int i = 1 ; i <= n ; ++i)cin >> a[i];
    sort(a + 1 , a + n + 1);
    fill_n(&dp[0][0],maxn*maxn,q + 1);
    while(l <= h){
        int mid = l + h >> 1;
        if(!chk(mid))l = mid + 1;
        else h = mid - 1;
//        return 0;
    }
    cout << l;
}


Compilation message

watching.cpp: In function 'int main()':
watching.cpp:52:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = l + h >> 1;
                   ~~^~~
watching.cpp:43:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:44:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 16204 KB Output is correct
2 Correct 18 ms 16128 KB Output is correct
3 Correct 18 ms 16128 KB Output is correct
4 Correct 19 ms 16128 KB Output is correct
5 Correct 16 ms 16000 KB Output is correct
6 Correct 19 ms 16128 KB Output is correct
7 Correct 15 ms 16128 KB Output is correct
8 Correct 17 ms 16128 KB Output is correct
9 Correct 15 ms 16000 KB Output is correct
10 Correct 16 ms 16128 KB Output is correct
11 Correct 15 ms 16000 KB Output is correct
12 Correct 19 ms 16128 KB Output is correct
13 Correct 19 ms 16000 KB Output is correct
14 Correct 16 ms 16128 KB Output is correct
15 Correct 17 ms 16000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 16072 KB Output is correct
2 Correct 17 ms 16128 KB Output is correct
3 Correct 181 ms 16164 KB Output is correct
4 Correct 190 ms 16156 KB Output is correct
5 Correct 32 ms 16128 KB Output is correct
6 Correct 199 ms 16248 KB Output is correct
7 Correct 20 ms 16128 KB Output is correct
8 Correct 37 ms 16128 KB Output is correct
9 Correct 121 ms 16128 KB Output is correct
10 Correct 177 ms 16128 KB Output is correct
11 Correct 33 ms 16128 KB Output is correct
12 Correct 146 ms 16248 KB Output is correct
13 Correct 24 ms 16128 KB Output is correct
14 Correct 21 ms 16128 KB Output is correct
15 Correct 19 ms 16128 KB Output is correct