Submission #805509

# Submission time Handle Problem Language Result Execution time Memory
805509 2023-08-03T17:18:13 Z hariaakas646 Watching (JOI13_watching) C++17
50 / 100
1000 ms 6272 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;

vi vec;
int n, p, q;

bool check(int w)
{
    vvi dp(n + 1, vi(p + 1));
    frange(i, p + 1) dp[0][i] = 0;
    forr(i, 1, n + 1)
    {
        frange(j, p + 1)
        {
            int v = 0;
            auto it = lower_bound(all(vec), vec[i] - 2 * w + 1);
            if (it != vec.begin())
            {
                it--;
                v = dp[it - vec.begin()][j];
            }
            dp[i][j] = v + 1;
            if (j > 0)
            {
                it = lower_bound(all(vec), vec[i] - w + 1);
                v = 0;
                if (it != vec.begin())
                {
                    it--;
                    v = dp[it - vec.begin()][j - 1];
                }
                dp[i][j] = min(dp[i][j], v);
            }
        }
    }
    return dp[n][p] <= q;
}

int main()
{

    scd(n);
    scd(p);
    scd(q);
    if (p + q >= n)
    {
        printf("1");
        return 0;
    }
    vec = vi(n + 1);
    forr(i, 1, n + 1) scd(vec[i]);
    sort(all(vec));
    int lo = 1;
    int hi = 1e9;

    while (lo != hi)
    {
        int mid = (lo + hi) / 2;
        if (check(mid))
        {
            hi = mid;
        }
        else
            lo = mid + 1;
    }
    printf("%d", lo);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
watching.cpp:65:5: note: in expansion of macro 'scd'
   65 |     scd(n);
      |     ^~~
watching.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
watching.cpp:66:5: note: in expansion of macro 'scd'
   66 |     scd(p);
      |     ^~~
watching.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
watching.cpp:67:5: note: in expansion of macro 'scd'
   67 |     scd(q);
      |     ^~~
watching.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
watching.cpp:74:23: note: in expansion of macro 'scd'
   74 |     forr(i, 1, n + 1) scd(vec[i]);
      |                       ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 5 ms 212 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 312 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 25 ms 468 KB Output is correct
8 Correct 177 ms 1372 KB Output is correct
9 Execution timed out 1049 ms 6272 KB Time limit exceeded
10 Halted 0 ms 0 KB -