Submission #130107

# Submission time Handle Problem Language Result Execution time Memory
130107 2019-07-14T00:44:49 Z Utaha Sparklers (JOI17_sparklers) C++14
100 / 100
36 ms 2984 KB
/*input
3 2 10
0
200
300
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<'('<<P.F<<','<<P.S<<')';
    return out;
}
 
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;
 
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        
        b>>=1;
    }
    return res;
}
int n,k;
ll t;
ll a[maxn];
ll x[maxn];

bool check(ll s){
    REP(i,n) x[i]=a[i]-2*t*s*i;
    if(x[0]<x[n-1]) return 0;
    int gl=max_element(x,x+k+1)-x;
    int gr=min_element(x+k,x+n)-x;

    {
        int l=k,r=k;
        while(l!=gl||r!=gr){
            int nxt=l;
            bool f=0;
            while(nxt>gl&&x[nxt-1]>=x[r]){
                nxt--;
                if(x[nxt]>=x[l]){
                    f=1;
                    break;
                }
            }
            if(f){
                l=nxt;
                continue;
            }
            nxt=r;
            while(nxt<gr&&x[nxt+1]<=x[l]){
                nxt++;
                if(x[nxt]<=x[r]){
                    f=1;
                    break;
                }
            }
            if(f){
                r=nxt;
                continue;
            }
            break;
        }
        if(l!=gl||r!=gr) return 0;
    }
    {
        int l=0,r=n-1;
        while(l!=gl||r!=gr){
            int nxt=l;
            bool f=0;
            while(nxt<gl&&x[nxt+1]>=x[r]){
                nxt++;
                if(x[nxt]>=x[l]){
                    f=1;
                    break;
                }
            }
            if(f){
                l=nxt;
                continue;
            }
            nxt=r;
            while(nxt>gr&&x[nxt-1]<=x[l]){
                nxt--;
                if(x[nxt]<=x[r]){
                    f=1;
                    break;
                }
            }
            if(f){
                r=nxt;
                continue;
            }
            break;
        }
        if(l!=gl||r!=gr) return 0;
    }
    return 1;
}
 
int main(){
    IOS;
    cin>>n>>k>>t;
    k--;
    REP(i,n) cin>>a[i];
    ll l=-1,r=1000000000LL;
    while(l!=r-1){
        ll mid=(l+r)/2;
        if(check(mid)) r=mid;
        else l=mid;
    }
    cout<<r<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 372 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 372 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 372 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 21 ms 2040 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 8 ms 888 KB Output is correct
44 Correct 31 ms 2808 KB Output is correct
45 Correct 32 ms 2940 KB Output is correct
46 Correct 34 ms 2808 KB Output is correct
47 Correct 36 ms 2808 KB Output is correct
48 Correct 35 ms 2936 KB Output is correct
49 Correct 33 ms 2936 KB Output is correct
50 Correct 32 ms 2812 KB Output is correct
51 Correct 35 ms 2936 KB Output is correct
52 Correct 32 ms 2948 KB Output is correct
53 Correct 35 ms 2936 KB Output is correct
54 Correct 33 ms 2860 KB Output is correct
55 Correct 34 ms 2872 KB Output is correct
56 Correct 32 ms 2936 KB Output is correct
57 Correct 32 ms 2936 KB Output is correct
58 Correct 33 ms 2936 KB Output is correct
59 Correct 26 ms 2040 KB Output is correct
60 Correct 30 ms 2808 KB Output is correct
61 Correct 32 ms 2808 KB Output is correct
62 Correct 32 ms 2940 KB Output is correct
63 Correct 30 ms 2792 KB Output is correct
64 Correct 30 ms 2984 KB Output is correct
65 Correct 31 ms 2936 KB Output is correct
66 Correct 31 ms 2780 KB Output is correct
67 Correct 30 ms 2936 KB Output is correct
68 Correct 31 ms 2808 KB Output is correct
69 Correct 29 ms 2808 KB Output is correct