Submission #657172

# Submission time Handle Problem Language Result Execution time Memory
657172 2022-11-09T03:12:35 Z hail Watching (JOI13_watching) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
using ll= long long;
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define inpint(x) int x; cin>>x
#define inpll(x) long long x; cin>>x
#define fl(i, n) for(int i=0; i<n; i++)
#define flo(i, n) for(int i=1; i<=n; i++)
#define int long long 
#define pi pair<int, int>
#define mp make_pair
#define ld long double
 
const int MOD = 7 + (int)1e9;
const int INF = (int)1e18;
 
//
 
int n, p, q;
int a[2005]{}
int dp[2005][2005]{};
 
bool check(int w)
{
    //p small q large
 
    for(int i=0; i<=p; i++)
    {
        for(int j=0; j<=q; j++)
        {
            //check p, q-1 and p-1, q
            if(j-1>=0)
            {
                int x = dp[i][j-1];
                auto it = upper_bound(a+1, a+n+1, x);
                int y = *it;
                int z = y + (2*w) - 1;
                it = upper_bound(a+1, a+n+1, z);
                it--;
                int t = *it;
                dp[i][j] = max(dp[i][j], t);
            }
            if(i-1>=0)
            {
                int x = dp[i-1][j];
                auto it = upper_bound(a+1, a+n+1, x);
                int y = *it;
                int z = y + (w) - 1;
                it = upper_bound(a+1, a+n+1, z);
                it--;
                int t = *it;
                dp[i][j] = max(dp[i][j], t);   
            }
 
            if(dp[i][j]>=a[n]) return true;
        }
    }
 
    return false;
}
 
void solve()
{
    cin>>n>>p>>q;
 
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
 
    sort(a+1, a+n+1);
 
    int low = 1;
    int high = 1000000000LL;
 
    if(p+q>=n)
    {
        cout<<1;
        return;
    }
 
    assert(p<=2000 && q<=2000);
 
    //assert(p<=2000 && q<=2000);
    int cnt = 0;
    while(high>low)
    {
        int mid = (high+low)/2;
        if(check(mid)) high = mid;
        else low = mid+1;
        cnt++;
        assert(cnt<40);
    }
 
    assert(high==low);
 
    cout<<high;
 
 
}
 
signed main()
{
    fast_io;
 
    int t=1; 
    //cin>>t;
    while(t--)
    {
        solve();
    }
    cout<<endl;
}

Compilation message

watching.cpp:15:13: error: expected ',' or ';' before 'long'
   15 | #define int long long
      |             ^~~~
watching.cpp:27:1: note: in expansion of macro 'int'
   27 | int dp[2005][2005]{};
      | ^~~
watching.cpp: In function 'bool check(long long int)':
watching.cpp:40:25: error: 'dp' was not declared in this scope; did you mean 'p'?
   40 |                 int x = dp[i][j-1];
      |                         ^~
      |                         p
watching.cpp:51:25: error: 'dp' was not declared in this scope; did you mean 'p'?
   51 |                 int x = dp[i-1][j];
      |                         ^~
      |                         p
watching.cpp:61:16: error: 'dp' was not declared in this scope; did you mean 'p'?
   61 |             if(dp[i][j]>=a[n]) return true;
      |                ^~
      |                p