Submission #895528

# Submission time Handle Problem Language Result Execution time Memory
895528 2023-12-30T07:35:58 Z nbphong Watching (JOI13_watching) C++14
100 / 100
146 ms 17752 KB
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define For(i,a,b) for(int i = (a), _b= (b) ; i<=_b ; i++)
#define pii pair<int,int>
#define ll long long
#define all(a) a.begin(),a.end()
#define pll pair<ll,ll>
#define pb push_back
#define AF "EVENTS"
using namespace std ;
const int N = 2100;
const int MOD = 998244353;
int f[N][N],n,w1,w2,a[N];
bool minimize(int &a,int b)
{
    if(a>b){
        a=b;return true;
    }else return false;
}
bool check(int mid)
{
    int l1=1,l2=1;
    memset(f,0x3f,sizeof f);
    memset(f[0],0,sizeof f[0]);
    For(i,1,n)
    {
        while(a[i]-a[l1]+1>mid) l1++;
        while(a[i]-a[l2]+1>2*mid) l2++;
        For(j,0,w1)
        {
            minimize(f[i][j+1],f[l1-1][j]);
            minimize(f[i][j],f[l2-1][j]+1);
        }
    }
    For(j,0,w1)  if(f[n][j]<=w2) return true;
    return false;
}
void enter()
{
    cin >> n >> w1 >> w2;
    if(w1+w2>=n){cout << 1; return;}
    For(i,1,n) cin >> a[i];
    sort(&a[1],&a[n+1]);
    int l = 1,r = 1e9;
    while(l<=r)
    {
        int mid = (l+r)>>1;
        if(check(mid)) r = mid-1;
        else l = mid+1;
    }
    cout << r+1;
}
void solve()
{

}
int main()
{
    fast;
    //freopen(AF".inp","r",stdin);
   // freopen(AF".out","w",stdout);
    enter();
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 25 ms 17500 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 27 ms 17496 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 29 ms 17752 KB Output is correct
8 Correct 30 ms 17500 KB Output is correct
9 Correct 27 ms 17500 KB Output is correct
10 Correct 24 ms 17532 KB Output is correct
11 Correct 33 ms 17500 KB Output is correct
12 Correct 25 ms 17500 KB Output is correct
13 Correct 25 ms 17500 KB Output is correct
14 Correct 26 ms 17720 KB Output is correct
15 Correct 31 ms 17496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 17500 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
7 Correct 27 ms 17500 KB Output is correct
8 Correct 35 ms 17500 KB Output is correct
9 Correct 74 ms 17496 KB Output is correct
10 Correct 146 ms 17752 KB Output is correct
11 Correct 38 ms 17496 KB Output is correct
12 Correct 93 ms 17704 KB Output is correct
13 Correct 27 ms 17496 KB Output is correct
14 Correct 28 ms 17500 KB Output is correct
15 Correct 29 ms 17500 KB Output is correct