Submission #624906

# Submission time Handle Problem Language Result Execution time Memory
624906 2022-08-09T02:53:19 Z Do_you_copy Watching (JOI13_watching) C++17
50 / 100
1000 ms 8328 KB
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
//#define int long long
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000007;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e3 + 10;
const int inf = 1e9;
int n, p, q;
int a[maxN];
ll dp[maxN][maxN];
int x[maxN];
int y[maxN];


bool check(int w){
    for (int i = 1; i <= n; ++i){
        x[i] = upper_bound(a + 1, a + n + 1, a[i] + w - 1) - a - 1;
        y[i] = upper_bound(a + 1, a + n + 1, a[i] + 2 * w - 1) - a - 1;
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= p; ++i){
        for (int j = 0; j <= q; ++j){
            if (i == 0 && j == 0) continue;
            if (i > 0) dp[i][j] = x[dp[i - 1][j] + 1];
            if (j > 0) dp[i][j] = max(dp[i][j], y[dp[i][j - 1] + 1]);
            if (dp[i][j] == n) return 1;
        }
    }
    return 0;
}

void Init(){
    cin >> n >> p >> q;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    if (p + q >= n){
        cout << 1;
        return;
    }
    sort(a + 1, a + n + 1);
    int l = 1, r = inf;
    while (l < r){
        int mid = (l + r) / 2;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }
    cout << l;
}

signed main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        //freopen(taskname".out", "w", stdout);
    }
    faster;
    ll tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream testout("timeout.txt");
        testout << double(clock()) / CLOCKS_PER_SEC;
        cerr << "\nTime elapsed: " << double(clock()) / CLOCKS_PER_SEC << "ms\n";
    }
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 8328 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 23 ms 8268 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 19 ms 8324 KB Output is correct
8 Correct 18 ms 8276 KB Output is correct
9 Correct 23 ms 8324 KB Output is correct
10 Correct 23 ms 8328 KB Output is correct
11 Correct 19 ms 8276 KB Output is correct
12 Correct 19 ms 8276 KB Output is correct
13 Correct 18 ms 8220 KB Output is correct
14 Correct 21 ms 8276 KB Output is correct
15 Correct 22 ms 8276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 352 KB Time limit exceeded
2 Halted 0 ms 0 KB -