Submission #1064424

# Submission time Handle Problem Language Result Execution time Memory
1064424 2024-08-18T12:34:17 Z Boycl07 Watching (JOI13_watching) C++17
50 / 100
1 ms 1112 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define int ll
#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "FFILL"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)

template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }


const int N = 1e3 + 3;
const int LIM = (1 << 16) + 3;
const int INF = 1e9 + 1;
const int LOG = 16;

int n, p, q;

int a[N];
int dp[N][N];

bool check(int w)
{
    forn(i, 0, n) forn(j, 0, p) dp[i][j] = INF;
    dp[0][0] = 0;
    int pos_w = 1, pos_2w = 1;
    rep(i, n)
    {
        while(pos_w <= n && a[pos_w] - a[i] + 1<= w) ++pos_w;
        while(pos_2w <= n && a[pos_2w] - a[i] + 1 <= 2 * w) ++pos_2w;

        forn(j, 0, p)
        {
            minimize(dp[pos_w - 1][j + 1], dp[i - 1][j]);
            minimize(dp[pos_2w - 1][j], dp[i - 1][j] + 1);
        }
    }

    forn(j, 0, p) if(dp[n][j] <= q) return 1;
    return 0;
}

void solve()
{
    cin >> n >> p >> q;
    rep(i, n) cin >> a[i];
    sort(a + 1, a + 1 + n);
    p = min(p, n);
    q = min(q, n);

    int l = 1, r = 1e9, res;
    while(l <= r)
    {
        int mid = l + r >> 1;
        if(check(mid)) res = mid, r = mid - 1;
        else l = mid + 1;
    }

    cout << res;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int TC = 1;

    if(fopen("note.inp", "r"))
    {
        freopen("note.inp", "r", stdin);
        freopen("note.out", "w", stdout);
    }


    while(TC--)
    {
        solve();
    }

    return 0;
}

Compilation message

watching.cpp: In function 'void solve()':
watching.cpp:70:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |         int mid = l + r >> 1;
      |                   ~~^~~
watching.cpp: In function 'int main()':
watching.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen("note.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen("note.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 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 720 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 0 ms 860 KB Output is correct
9 Correct 0 ms 860 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 1 ms 856 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 0 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -