Submission #71466

# Submission time Handle Problem Language Result Execution time Memory
71466 2018-08-24T18:47:16 Z claudy Watching (JOI13_watching) C++14
50 / 100
669 ms 64004 KB
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

int dp[2005][2005];
int n,p,q;
int a[2005];

const int mx = 1e18;

int check(int w)
{
    for(int i = 0;i <= n;i++)
    {
        for(int j = 0;j <= p;j++)
        {
            dp[i][j] = 1e18;
        }
    }
    for(int j = 0;j <= p;j++) dp[0][j] = 0;
    for(int i = 1;i <= n;i++)
    {
        int x = lower_bound(a + 1,a + 1 + n,a[i] - w + 1) - a;
        int y = lower_bound(a + 1,a + 1 + n,a[i] - 2*w + 1) - a;
        for(int j = p;j >= 0;j--)
        {
            dp[i][j] = min((j > 0 ? dp[x - 1][j - 1] : mx),dp[y - 1][j] + 1);
        }
    }
    return (dp[n][p] <= q);
}

int32_t main(){_
    //freopen("input","r",stdin);
    cin >> n >> p >> q;
    for(int i = 1;i <= n;i++) cin >> a[i];
    int l = 1;
    int r = 1e9;
    sort(a + 1,a + 1 + n);
    while(l < r)
    {
        int mid = l + r >> 1;
        if(check(mid)) r = mid;
        else l = mid + 1;
    }
    rc(l);
}

Compilation message

watching.cpp: In function 'int32_t main()':
watching.cpp:54:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = l + r >> 1;
                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 669 ms 2936 KB Output is correct
5 Correct 3 ms 2936 KB Output is correct
6 Correct 660 ms 3064 KB Output is correct
7 Correct 3 ms 3064 KB Output is correct
8 Correct 4 ms 3064 KB Output is correct
9 Correct 3 ms 3064 KB Output is correct
10 Correct 3 ms 3064 KB Output is correct
11 Correct 4 ms 3064 KB Output is correct
12 Correct 3 ms 3064 KB Output is correct
13 Correct 3 ms 3064 KB Output is correct
14 Correct 3 ms 3064 KB Output is correct
15 Correct 3 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8840 KB Output is correct
2 Correct 4 ms 8840 KB Output is correct
3 Correct 383 ms 32264 KB Output is correct
4 Runtime error 183 ms 64004 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -