제출 #624908

#제출 시각아이디문제언어결과실행 시간메모리
624908Do_you_copyWatching (JOI13_watching)C++17
100 / 100
165 ms32084 KiB
#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 = 2e3 + 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";
    }
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...