Submission #638577

# Submission time Handle Problem Language Result Execution time Memory
638577 2022-09-06T12:23:54 Z ghostwriter Watching (JOI13_watching) C++14
100 / 100
405 ms 16032 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Cay ngay cay dem nhung deo duoc cong nhan
*/
const int oo = 1e9;
const int N = 2e3 + 2;
int n, p, q, a[N], d[N][N], f[N], f1[N];
bool check(int w) {
	FOR(i, 1, n) {
		FOS(j, i, 1) {
			if (a[j] >= a[i] - w + 1) f[i] = j;
			if (a[j] >= a[i] - 2 * w + 1) f1[i] = j;
		}
	}
	FOR(i, 1, n)
	FOR(j, 0, p) {
		d[i][j] = oo;
		if (j) {
			int pos = f[i];
			d[i][j] = min(d[i][j], d[pos - 1][j - 1]);
		}
		int pos = f1[i];
		d[i][j] = min(d[i][j], d[pos - 1][j] + 1);
	}
	return d[n][p] <= q;
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // freopen(file".inp", "r", stdin);
    // freopen(file".out", "w", stdout);
    cin >> n >> p >> q;
    FOR(i, 1, n) cin >> a[i];
    sort(a + 1, a + 1 + n);
    p = min(p, n);
    q = min(q, n);
    int l = 1, r = 1e9, ans = -1;
    WHILE(l <= r) {
    	int mid = l + (r - l) / 2;
    	if (check(mid)) {
    		ans = mid;
    		r = mid - 1;
    	}
    	else l = mid + 1;
    }
    cout << ans;
    return 0;
}

Compilation message

watching.cpp: In function 'bool check(int)':
watching.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
watching.cpp:40:2: note: in expansion of macro 'FOR'
   40 |  FOR(i, 1, n) {
      |  ^~~
watching.cpp:25:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   25 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
watching.cpp:41:3: note: in expansion of macro 'FOS'
   41 |   FOS(j, i, 1) {
      |   ^~~
watching.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
watching.cpp:46:2: note: in expansion of macro 'FOR'
   46 |  FOR(i, 1, n)
      |  ^~~
watching.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
watching.cpp:47:2: note: in expansion of macro 'FOR'
   47 |  FOR(j, 0, p) {
      |  ^~~
watching.cpp: In function 'int main()':
watching.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
watching.cpp:63:5: note: in expansion of macro 'FOR'
   63 |     FOR(i, 1, n) cin >> a[i];
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 8392 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 365 ms 16024 KB Output is correct
4 Correct 373 ms 15956 KB Output is correct
5 Correct 73 ms 8980 KB Output is correct
6 Correct 379 ms 15960 KB Output is correct
7 Correct 71 ms 8492 KB Output is correct
8 Correct 88 ms 9328 KB Output is correct
9 Correct 193 ms 14260 KB Output is correct
10 Correct 405 ms 16024 KB Output is correct
11 Correct 82 ms 9080 KB Output is correct
12 Correct 273 ms 16032 KB Output is correct
13 Correct 73 ms 8472 KB Output is correct
14 Correct 74 ms 8532 KB Output is correct
15 Correct 70 ms 8512 KB Output is correct