답안 #385440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
385440 2021-04-04T09:32:15 Z ffao Sparklers (JOI17_sparklers) C++17
100 / 100
371 ms 5964 KB
#if 1
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG 1
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

#include <bits/stdc++.h>
using namespace std;

#if 0
    #include <bits/extc++.h>
    using namespace __gnu_pbds;

    template<class T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;
#endif

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)

typedef string str;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }

mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());

#define ts to_string
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) { str res = ""; F0R(i,SZ) res += char('0'+b[i]); return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { bool fst = 1; str res = "{"; for (const auto& x: v) {if (!fst) res += ", ";	fst = 0; res += ts(x);}	res += "}"; return res;}
template<class A, class B> str ts(pair<A,B> p) {return "("+ts(p.first)+", "+ts(p.second)+")"; }
 
template<class A> void pr(A x) { cout << ts(x); }
template<class H, class... T> void pr(const H& h, const T&... t) { pr(h); pr(t...); }
void ps() { pr("\n"); }
template<class H, class... T> void ps(const H& h, const T&... t) { pr(h); if (sizeof...(t)) pr(" "); ps(t...); }
 
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {cerr << ts(h); if (sizeof...(t)) cerr << ", ";	DBG(t...); }

int myrand(int l, int r) { return uniform_int_distribution(l, r)(rng); }

#endif

bool go(const vector<ll> &pl, const vector<ll> &pr) {
    vector<long long> left_max_pref(sz(pl));
    vector<long long> right_max_pref(sz(pr));
    
    for (int i = 0; i < sz(pl); i++) {
        left_max_pref[i] = i==0 ? pl[i] : max(left_max_pref[i-1], pl[i]);
    }
    for (int i = 0; i < sz(pr); i++) {
        right_max_pref[i] = i==0 ? pr[i] : max(right_max_pref[i-1], pr[i]);
    }

    vector< int > minimums_left;
    vector< int > minimums_right;

    for (int i = 0; i < sz(pl); i++) {
        if (minimums_left.empty() || pl[minimums_left.back()] >= pl[i]) {
            minimums_left.push_back(i);
        }
    }
    for (int i = 0; i < sz(pr); i++) {
        if (minimums_right.empty() || pr[minimums_right.back()] >= pr[i]) {
            minimums_right.push_back(i);
        }
    }

    int cur_left = 0, cur_right = 0;
    while (cur_left+1 != sz(minimums_left) || cur_right+1 != sz(minimums_right)) {
        // dbg(cur_left, cur_right, minimums_left, minimums_right, pl[minimums_left[cur_left]], pr[minimums_right[cur_right]]);
        bool moved = false;

        if (cur_left+1 != sz(minimums_left) && pr[minimums_right[cur_right]] + left_max_pref[minimums_left[cur_left+1]] <= 0) {
            cur_left++;
            moved = true;
        }

        if (cur_right+1 != sz(minimums_right) && pl[minimums_left[cur_left]] + right_max_pref[minimums_right[cur_right+1]] <= 0) {
            cur_right++;
            moved = true;
        }

        if (!moved) return false;
    }

    return true;
}

bool check(long long speed, vector<ll> left, vector<ll> right, int t) {
    if (t * 1ll * speed * 2 >= 1000000000) return true;

    for (auto &x : left) x -= (t * 1ll * speed * 2);
    for (auto &x : right) x -= (t * 1ll * speed * 2);

    // dbg(left, right);

    vector<long long> pl(sz(left)+1), pr(sz(right)+1);
    partial_sum(all(left), pl.begin()+1);
    partial_sum(all(right), pr.begin()+1);

    // dbg(pl, pr);

    bool ok = go(pl, pr);
    reverse(all(pl));
    reverse(all(pr));
    ok = ok && go(pl, pr);

    return ok;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k, t;
    cin >> n >> k >> t; k--;

    vector<ll> left, right;
    
    vi a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    for (int i = 0; i < n; i++) {
        if (i < k) {
            left.push_back(a[i+1] - a[i]);
        }
        else if (i > k) {
            right.push_back(a[i] - a[i-1]);
        }
    }

    reverse(all(left));

    // bool o =check(6, left, right, t);
    // dbg(o);

    long long st = 0, ed = 1000000000;
    while (st < ed) {
        // dbg(st,ed);
        long long md = (st+ed)/2;
        if (check(md, left, right, t)) ed = md;
        else st=md+1;
    }

    cout << st << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 3 ms 364 KB Output is correct
23 Correct 3 ms 364 KB Output is correct
24 Correct 4 ms 364 KB Output is correct
25 Correct 4 ms 364 KB Output is correct
26 Correct 5 ms 364 KB Output is correct
27 Correct 4 ms 364 KB Output is correct
28 Correct 5 ms 364 KB Output is correct
29 Correct 4 ms 364 KB Output is correct
30 Correct 4 ms 364 KB Output is correct
31 Correct 4 ms 364 KB Output is correct
32 Correct 4 ms 364 KB Output is correct
33 Correct 4 ms 364 KB Output is correct
34 Correct 4 ms 364 KB Output is correct
35 Correct 4 ms 364 KB Output is correct
36 Correct 4 ms 364 KB Output is correct
37 Correct 4 ms 364 KB Output is correct
38 Correct 4 ms 364 KB Output is correct
39 Correct 5 ms 364 KB Output is correct
40 Correct 4 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 3 ms 364 KB Output is correct
23 Correct 3 ms 364 KB Output is correct
24 Correct 4 ms 364 KB Output is correct
25 Correct 4 ms 364 KB Output is correct
26 Correct 5 ms 364 KB Output is correct
27 Correct 4 ms 364 KB Output is correct
28 Correct 5 ms 364 KB Output is correct
29 Correct 4 ms 364 KB Output is correct
30 Correct 4 ms 364 KB Output is correct
31 Correct 4 ms 364 KB Output is correct
32 Correct 4 ms 364 KB Output is correct
33 Correct 4 ms 364 KB Output is correct
34 Correct 4 ms 364 KB Output is correct
35 Correct 4 ms 364 KB Output is correct
36 Correct 4 ms 364 KB Output is correct
37 Correct 4 ms 364 KB Output is correct
38 Correct 4 ms 364 KB Output is correct
39 Correct 5 ms 364 KB Output is correct
40 Correct 4 ms 364 KB Output is correct
41 Correct 217 ms 3860 KB Output is correct
42 Correct 10 ms 492 KB Output is correct
43 Correct 59 ms 1356 KB Output is correct
44 Correct 345 ms 5856 KB Output is correct
45 Correct 344 ms 5676 KB Output is correct
46 Correct 333 ms 5964 KB Output is correct
47 Correct 364 ms 5948 KB Output is correct
48 Correct 350 ms 5660 KB Output is correct
49 Correct 347 ms 5892 KB Output is correct
50 Correct 355 ms 5688 KB Output is correct
51 Correct 352 ms 5956 KB Output is correct
52 Correct 347 ms 5876 KB Output is correct
53 Correct 350 ms 5948 KB Output is correct
54 Correct 362 ms 5908 KB Output is correct
55 Correct 334 ms 5732 KB Output is correct
56 Correct 341 ms 5944 KB Output is correct
57 Correct 354 ms 5904 KB Output is correct
58 Correct 347 ms 5596 KB Output is correct
59 Correct 362 ms 4900 KB Output is correct
60 Correct 352 ms 5916 KB Output is correct
61 Correct 360 ms 5804 KB Output is correct
62 Correct 331 ms 5828 KB Output is correct
63 Correct 353 ms 5828 KB Output is correct
64 Correct 348 ms 5736 KB Output is correct
65 Correct 346 ms 5536 KB Output is correct
66 Correct 371 ms 5644 KB Output is correct
67 Correct 343 ms 5660 KB Output is correct
68 Correct 347 ms 5708 KB Output is correct
69 Correct 355 ms 5784 KB Output is correct