답안 #30042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30042 2017-07-21T18:23:09 Z samir_droubi 구경하기 (JOI13_watching) C++14
100 / 100
613 ms 17744 KB
#include <bits/stdc++.h>
using namespace std;
int n,p,q;
const int mxn=2005;
int dp[mxn][mxn];
int a[mxn];
int l[mxn];
int l2[mxn];
int calc(int i,int u)
{
    if(dp[i][u] != -1)  return dp[i][u];
    if( u > p )return (1e9);
    if(i == 0 ) return 0;
    int ans = calc( l[i] - 1 , u + 1 );
    ans = min(ans , 1 + calc( l2[i] - 1 , u ) );
    return dp[i][u] = ans;
}
bool check(int w)
{
    memset(dp,-1,sizeof dp);
    l[0] = 1;
    l2[0] = 1;
    for(int i = 1; i <= n ; ++i)
    {
        l[i] = l[i - 1];
        l2[i] = l2[i - 1];
        while(a[i] - a[ l[i] ] + 1 > w) ++l[i];
        while(a[i] - a[ l2[i] ] + 1 > 2*w) ++l2[i];
    }
    return calc( n , 0 ) <= q;
}
void bs()
{
    int l=1;
    int r=(1e9);
    int ans=-1;
    while( l <= r )
    {
        int md = ( l + r ) / 2;
        if( check( md ) )r = md - 1 , ans = md;
        else l = md + 1;
    }
    printf("%d\n",ans);
}
int main()
{
    scanf("%d%d%d",&n,&p,&q);
    for(int i = 1 ; i <= n ; ++i )
        scanf("%d",&a[i]);
    sort( a + 1 , a + n + 1 );
    bs();
    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:47:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&p,&q);
                             ^
watching.cpp:49:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 17744 KB Output is correct
2 Correct 33 ms 17744 KB Output is correct
3 Correct 66 ms 17744 KB Output is correct
4 Correct 33 ms 17744 KB Output is correct
5 Correct 33 ms 17744 KB Output is correct
6 Correct 29 ms 17744 KB Output is correct
7 Correct 33 ms 17744 KB Output is correct
8 Correct 33 ms 17744 KB Output is correct
9 Correct 36 ms 17744 KB Output is correct
10 Correct 39 ms 17744 KB Output is correct
11 Correct 36 ms 17744 KB Output is correct
12 Correct 36 ms 17744 KB Output is correct
13 Correct 29 ms 17744 KB Output is correct
14 Correct 36 ms 17744 KB Output is correct
15 Correct 46 ms 17744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 17744 KB Output is correct
2 Correct 39 ms 17744 KB Output is correct
3 Correct 463 ms 17744 KB Output is correct
4 Correct 516 ms 17744 KB Output is correct
5 Correct 129 ms 17744 KB Output is correct
6 Correct 529 ms 17744 KB Output is correct
7 Correct 43 ms 17744 KB Output is correct
8 Correct 129 ms 17744 KB Output is correct
9 Correct 236 ms 17744 KB Output is correct
10 Correct 613 ms 17744 KB Output is correct
11 Correct 153 ms 17744 KB Output is correct
12 Correct 499 ms 17744 KB Output is correct
13 Correct 86 ms 17744 KB Output is correct
14 Correct 56 ms 17744 KB Output is correct
15 Correct 69 ms 17744 KB Output is correct