Submission #423381

# Submission time Handle Problem Language Result Execution time Memory
423381 2021-06-11T04:40:46 Z balbit Sparklers (JOI17_sparklers) C++14
100 / 100
54 ms 3784 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define y1 zck_is_king
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define REP(i,n) for (int i = 0; i<n; ++i)
#define RREP(i,n) for (int i = n-1; i>=0; --i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 2e18+10000;
const ll mod = 1e9+7 ;


void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 1e6+5;

int n,k,T;

bool spread(vector<ll> a) {
    int n = SZ(a);
    int Lp=k, Rp=k;
    //
    REP(i, k+1) {
        if (a[i] > a[Lp]) Lp = i;
    }
    for (int i = k; i<n; ++i) {
        if (a[i] < a[Rp]) Rp = i;
    }
    bug(Lp, Rp);
    // try to spread [k,k] to [Lp, Rp], maintaining a[L] >= a[R]

    int nowl = k, nowr = k;
    int lcan = k, rcan = k; // where l,r can go as of now (but not peaks)
    bool chg = 1;
    while (chg) {
        chg = 0;
        while (Lp < lcan) {
//            bug(lcan, rcan);
            if (a[lcan-1] >= a[nowr] ) {
                --lcan;
                if (a[lcan] >= a[nowl]) {
                    nowl = lcan; chg = 1;
                }
            }else break;
        }
        while (rcan < Rp) {
            if (a[rcan+1] <= a[nowl]) {
                ++rcan;
                if (a[rcan] <= a[nowr]) {
                    nowr = rcan; chg = 1;
                }
            }else break;
        }
        bug(lcan, rcan);
    }
    bug(nowl, nowr, Lp, Rp);
    if (nowl != Lp || nowr != Rp) return 0;

    if (a[0] < a[n-1]) return 0;
    nowl = 0, nowr = n-1; // spreading backwards now
    lcan = 0, rcan = n-1;
    chg = 1;
//    bug("hey");
    while (chg) {
        chg = 0;
        while (lcan < Lp) {
            if (a[lcan+1] >= a[nowr]) {
                ++lcan;
                if(a[lcan] >= a[nowl]) {
                    nowl = lcan; chg = 1;
                }
            }else break;
        }
        while (rcan > Rp) {
            if (a[rcan-1] <= a[nowl]) {
                --rcan;
                if (a[rcan] <= a[nowr]) {
                    nowr = rcan; chg = 1;
                }
            }else break;
        }
        bug(lcan, rcan);
    }

//    if (a[nowr] > a[rcan]) assert(0);

    bug(nowl, nowr, lcan, rcan, Lp, Rp);
    if (nowl != Lp || nowr != Rp) return 0;
    return 1;
}

signed main(){
    IOS();
   cin>>n>>k>>T;
    --k;
    vector<ll> X(n);
    REP(i,n) {
        cin>>X[i];
    }
//    for (int x : L) bug(x);
//    for (int x : R) bug(x);

//    bug(st);
    ll l = 0, r = 1e9+5;
    while (l!=r) {
        ll s = (l+r)/2;
        if (s * T * 2> 1000000000ll * 2) {
            r = s; continue;
        }
        vector<ll> a(n);
        REP(i,n) {
            a[i] = X[i] - 2 * s * T * i;
        }
        bug(l,r, s);
        bool ok = spread(a);
        if (!ok) {
            l = s+1;
        }else{
            r = s;
        }
    }
    cout<<l<<endl;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 27 ms 2540 KB Output is correct
42 Correct 2 ms 360 KB Output is correct
43 Correct 7 ms 940 KB Output is correct
44 Correct 50 ms 3620 KB Output is correct
45 Correct 43 ms 3644 KB Output is correct
46 Correct 44 ms 3716 KB Output is correct
47 Correct 47 ms 3628 KB Output is correct
48 Correct 48 ms 3680 KB Output is correct
49 Correct 45 ms 3712 KB Output is correct
50 Correct 45 ms 3684 KB Output is correct
51 Correct 44 ms 3712 KB Output is correct
52 Correct 43 ms 3648 KB Output is correct
53 Correct 49 ms 3644 KB Output is correct
54 Correct 48 ms 3704 KB Output is correct
55 Correct 41 ms 3624 KB Output is correct
56 Correct 43 ms 3688 KB Output is correct
57 Correct 54 ms 3696 KB Output is correct
58 Correct 44 ms 3712 KB Output is correct
59 Correct 36 ms 2916 KB Output is correct
60 Correct 44 ms 3716 KB Output is correct
61 Correct 41 ms 3540 KB Output is correct
62 Correct 41 ms 3636 KB Output is correct
63 Correct 42 ms 3692 KB Output is correct
64 Correct 44 ms 3708 KB Output is correct
65 Correct 44 ms 3624 KB Output is correct
66 Correct 44 ms 3672 KB Output is correct
67 Correct 41 ms 3628 KB Output is correct
68 Correct 43 ms 3784 KB Output is correct
69 Correct 41 ms 3620 KB Output is correct