답안 #624907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
624907 2022-08-09T02:53:46 Z Do_you_copy 구경하기 (JOI13_watching) C++17
50 / 100
24 ms 8320 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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 8276 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 17 ms 8320 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 24 ms 8320 KB Output is correct
8 Correct 24 ms 8276 KB Output is correct
9 Correct 19 ms 8292 KB Output is correct
10 Correct 20 ms 8320 KB Output is correct
11 Correct 19 ms 8276 KB Output is correct
12 Correct 18 ms 8316 KB Output is correct
13 Correct 16 ms 8276 KB Output is correct
14 Correct 18 ms 8276 KB Output is correct
15 Correct 23 ms 8276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -