Submission #946950

# Submission time Handle Problem Language Result Execution time Memory
946950 2024-03-15T08:13:39 Z hariaakas646 Watching (JOI13_watching) C++17
100 / 100
489 ms 30576 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, l, r) for(int i=l; i<r; i++)
#define frange(i, l) forr(i, 0, l)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
 
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef long long lli;
typedef vector<vi> vvi;
typedef vector<lli> vll;
typedef vector<bool> vb;
typedef set<int> seti;
typedef multiset<int> mseti;
 
void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

int n, p, q;
vll vec;

bool check(lli w) {
    vector<vll> dp(n, vll(q+1, 1e9));
    frange(i, q+1) dp[0][i] = 0;
    dp[0][0] = 1;

    int i1 = -1;
    int i2 = -1;
    
    

    forr(i, 1, n) {
        while(i1 < n-1 && vec[i1+1] <= vec[i] - w) i1++;
        while(i2 < n-1 && vec[i2+1] <= vec[i] - 2 * w) i2++;
        frange(j, q+1) {
            
            if(i1 != -1)
                dp[i][j] = dp[i1][j] + 1;
            else dp[i][j] = 1;
            
            if(j >= 1) {
                if(i2 != -1)
                    dp[i][j] = min(dp[i][j], dp[i2][j-1]); 
                else dp[i][j] = 0;
            }
        }
    }
    lli mi = 1e9;
    frange(i, q+1) mi = min(mi, dp[n-1][i]);
    return mi <= p;
}

int main() {
    // usaco();
    scd(n);
    scd(p);
    scd(q);

    vec = vll(n);
    frange(i, n) sclld(vec[i]);
    sort(all(vec));
    if(p + q>=n) {
        printf("1");
        return 0;
    }
    else {
        lli lo = 0;
        lli hi = 1e9;

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

Compilation message

watching.cpp: In function 'void usaco()':
watching.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:67:5: note: in expansion of macro 'scd'
   67 |     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:68:5: note: in expansion of macro 'scd'
   68 |     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:69:5: note: in expansion of macro 'scd'
   69 |     scd(q);
      |     ^~~
watching.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define sclld(t) scanf("%lld", &t)
      |                  ~~~~~^~~~~~~~~~~~
watching.cpp:72:18: note: in expansion of macro 'sclld'
   72 |     frange(i, n) sclld(vec[i]);
      |                  ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 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 440 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 173 ms 12416 KB Output is correct
9 Correct 28 ms 2548 KB Output is correct
10 Correct 21 ms 1916 KB Output is correct
11 Correct 489 ms 30576 KB Output is correct
12 Correct 241 ms 15984 KB Output is correct
13 Correct 6 ms 820 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 6 ms 792 KB Output is correct