Submission #30042

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
300422017-07-21 18:23:09samir_droubiWatching (JOI13_watching)C++14
100 / 100
613 ms17744 KiB
#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;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Compilation message (stderr)

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]);
                          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...