Submission #363256

# Submission time Handle Problem Language Result Execution time Memory
363256 2021-02-05T11:47:17 Z denkendoemeer Sparklers (JOI17_sparklers) C++14
100 / 100
43 ms 2924 KB
#include<bits/stdc++.h>
#define ll long long
const ll inf=1e18;
using namespace std;
ll t,x[100005],dp[100005];
int n,k;
bool calc(ll nr)
{
    nr=nr*2;
    if (t*nr>(ll)1e9)
        return 1;
    int i;
    for(i=1;i<=n;i++)
        dp[i]=x[i]-i*t*nr;
    int st=1,dr=n;
    for(i=1;i<=k;i++)
        if (dp[st]<=dp[i])
            st=i;
    for(i=k;i<=n;i++)
        if (dp[dr]>=dp[i])
            dr=i;
    int l=k,r=k;
    ll v1=dp[l],v2=dp[r];
    while(st<=l || r<=dr){
        int auxl=l,auxr=r;
        while(l>=st && dp[l]>=v2){
            v1=max(v1,dp[l]);
            l--;
        }
        while(r<=dr && dp[r]<=v1){
            v2=min(v2,dp[r]);
            r++;
        }
        if (l==auxl && r==auxr)
            return 0;
    }
    l=1;
    r=n;
    v1=dp[l];
    v2=dp[r];
    while(l<=st || dr<=r){
        int auxl=l,auxr=r;
        while(l<=st && dp[l]>=v2){
            v1=max(v1,dp[l]);
            l++;
        }
        while(r>=dr && dp[r]<=v1){
            v2=min(v2,dp[r]);
            r--;
        }
        if (l==auxl && r==auxr)
            return 0;
    }
    return 1;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d%d%lld",&n,&k,&t);
    int i;
    for(i=1;i<=n;i++)
        scanf("%lld",&x[i]);
    ll st=0,dr=1e9,mij,last;
    while(st<=dr){
        mij=(st+dr)/2;
        if (calc(mij)){
            last=mij;
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    printf("%lld\n",last);
return 0;
}

Compilation message

sparklers.cpp: In function 'int main()':
sparklers.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   60 |     scanf("%d%d%lld",&n,&k,&t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |         scanf("%lld",&x[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 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 1 ms 384 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 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 1 ms 384 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 22 ms 2028 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 6 ms 748 KB Output is correct
44 Correct 34 ms 2796 KB Output is correct
45 Correct 30 ms 2796 KB Output is correct
46 Correct 30 ms 2796 KB Output is correct
47 Correct 32 ms 2796 KB Output is correct
48 Correct 31 ms 2796 KB Output is correct
49 Correct 43 ms 2796 KB Output is correct
50 Correct 32 ms 2796 KB Output is correct
51 Correct 31 ms 2924 KB Output is correct
52 Correct 30 ms 2924 KB Output is correct
53 Correct 41 ms 2924 KB Output is correct
54 Correct 32 ms 2800 KB Output is correct
55 Correct 42 ms 2796 KB Output is correct
56 Correct 30 ms 2796 KB Output is correct
57 Correct 30 ms 2796 KB Output is correct
58 Correct 30 ms 2796 KB Output is correct
59 Correct 28 ms 2028 KB Output is correct
60 Correct 31 ms 2796 KB Output is correct
61 Correct 30 ms 2712 KB Output is correct
62 Correct 31 ms 2796 KB Output is correct
63 Correct 33 ms 2796 KB Output is correct
64 Correct 32 ms 2796 KB Output is correct
65 Correct 31 ms 2924 KB Output is correct
66 Correct 34 ms 2824 KB Output is correct
67 Correct 35 ms 2912 KB Output is correct
68 Correct 31 ms 2884 KB Output is correct
69 Correct 30 ms 2796 KB Output is correct