Submission #85503

# Submission time Handle Problem Language Result Execution time Memory
85503 2018-11-20T15:31:32 Z nikolapesic2802 Sparklers (JOI17_sparklers) C++14
100 / 100
112 ms 28248 KB
#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;

int main()
{
    int n,k,t;
    scanf("%i %i %i",&n,&k,&t);
    vector<int> arr(n+1);
    for(int i=1;i<=n;i++)
    {
        scanf("%i",&arr[i]);
    }
    int le=0,ri=1e9;
    while(le<ri)
    {
        int m=(le+ri)/2;
        vector<long double> X(n+1);
        for(int i=1;i<=n;i++)
        {
            X[i]=arr[i]-(long double)2*m*t*(i-1);
        }
        int l=k,r=k;
        int minn=k,maxx=k;
        int ok=1;
        while(ok)
        {
            ok=0;
            while(l>1&&X[l-1]>=X[minn])
            {
                ok=1;
                if(X[--l]>X[maxx])maxx=l;
            }
            while(r<n&&X[r+1]<=X[maxx])
            {
                ok=1;
                if(X[++r]<X[minn])minn=r;
            }
        }
        if(l==1&&r==n)
        {
            minn=1,maxx=n;
            if(X[minn]<X[maxx])
            {
                le=m+1;
                continue;
            }
            maxx=1;
            minn=n;
            ok=1;
            while(ok)
            {
                ok=0;
                while(l<k&&X[l+1]>=X[minn])
                {
                    ok=1;
                    if(X[++l]>X[maxx])maxx=l;
                }
                while(r>k&&X[r-1]<=X[maxx])
                {
                    ok=1;
                    if(X[--r]<X[minn])minn=r;
                }
            }
            if(r==k&&l==k)
            {
                ri=m;
            }
            else
            {
                le=m+1;
            }
        }
        else
        {
            le=m+1;
        }
    }
    printf("%i\n",le);
    return 0;
}

Compilation message

sparklers.cpp: In function 'int main()':
sparklers.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %i %i",&n,&k,&t);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&arr[i]);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 3 ms 500 KB Output is correct
5 Correct 2 ms 500 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 2 ms 568 KB Output is correct
10 Correct 2 ms 568 KB Output is correct
11 Correct 3 ms 568 KB Output is correct
12 Correct 2 ms 568 KB Output is correct
13 Correct 2 ms 776 KB Output is correct
14 Correct 2 ms 792 KB Output is correct
15 Correct 2 ms 828 KB Output is correct
16 Correct 2 ms 828 KB Output is correct
17 Correct 2 ms 828 KB Output is correct
18 Correct 2 ms 828 KB Output is correct
19 Correct 3 ms 828 KB Output is correct
20 Correct 2 ms 828 KB Output is correct
21 Correct 3 ms 828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 3 ms 500 KB Output is correct
5 Correct 2 ms 500 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 2 ms 568 KB Output is correct
10 Correct 2 ms 568 KB Output is correct
11 Correct 3 ms 568 KB Output is correct
12 Correct 2 ms 568 KB Output is correct
13 Correct 2 ms 776 KB Output is correct
14 Correct 2 ms 792 KB Output is correct
15 Correct 2 ms 828 KB Output is correct
16 Correct 2 ms 828 KB Output is correct
17 Correct 2 ms 828 KB Output is correct
18 Correct 2 ms 828 KB Output is correct
19 Correct 3 ms 828 KB Output is correct
20 Correct 2 ms 828 KB Output is correct
21 Correct 3 ms 828 KB Output is correct
22 Correct 3 ms 876 KB Output is correct
23 Correct 3 ms 884 KB Output is correct
24 Correct 2 ms 908 KB Output is correct
25 Correct 4 ms 948 KB Output is correct
26 Correct 3 ms 976 KB Output is correct
27 Correct 3 ms 1004 KB Output is correct
28 Correct 3 ms 1032 KB Output is correct
29 Correct 3 ms 1044 KB Output is correct
30 Correct 3 ms 1056 KB Output is correct
31 Correct 3 ms 1072 KB Output is correct
32 Correct 3 ms 1084 KB Output is correct
33 Correct 3 ms 1084 KB Output is correct
34 Correct 3 ms 1108 KB Output is correct
35 Correct 3 ms 1120 KB Output is correct
36 Correct 3 ms 1132 KB Output is correct
37 Correct 3 ms 1144 KB Output is correct
38 Correct 3 ms 1156 KB Output is correct
39 Correct 3 ms 1168 KB Output is correct
40 Correct 3 ms 1172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 3 ms 500 KB Output is correct
5 Correct 2 ms 500 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 2 ms 568 KB Output is correct
10 Correct 2 ms 568 KB Output is correct
11 Correct 3 ms 568 KB Output is correct
12 Correct 2 ms 568 KB Output is correct
13 Correct 2 ms 776 KB Output is correct
14 Correct 2 ms 792 KB Output is correct
15 Correct 2 ms 828 KB Output is correct
16 Correct 2 ms 828 KB Output is correct
17 Correct 2 ms 828 KB Output is correct
18 Correct 2 ms 828 KB Output is correct
19 Correct 3 ms 828 KB Output is correct
20 Correct 2 ms 828 KB Output is correct
21 Correct 3 ms 828 KB Output is correct
22 Correct 3 ms 876 KB Output is correct
23 Correct 3 ms 884 KB Output is correct
24 Correct 2 ms 908 KB Output is correct
25 Correct 4 ms 948 KB Output is correct
26 Correct 3 ms 976 KB Output is correct
27 Correct 3 ms 1004 KB Output is correct
28 Correct 3 ms 1032 KB Output is correct
29 Correct 3 ms 1044 KB Output is correct
30 Correct 3 ms 1056 KB Output is correct
31 Correct 3 ms 1072 KB Output is correct
32 Correct 3 ms 1084 KB Output is correct
33 Correct 3 ms 1084 KB Output is correct
34 Correct 3 ms 1108 KB Output is correct
35 Correct 3 ms 1120 KB Output is correct
36 Correct 3 ms 1132 KB Output is correct
37 Correct 3 ms 1144 KB Output is correct
38 Correct 3 ms 1156 KB Output is correct
39 Correct 3 ms 1168 KB Output is correct
40 Correct 3 ms 1172 KB Output is correct
41 Correct 72 ms 3240 KB Output is correct
42 Correct 4 ms 3240 KB Output is correct
43 Correct 17 ms 3240 KB Output is correct
44 Correct 80 ms 5108 KB Output is correct
45 Correct 82 ms 6072 KB Output is correct
46 Correct 82 ms 6940 KB Output is correct
47 Correct 87 ms 8000 KB Output is correct
48 Correct 83 ms 8864 KB Output is correct
49 Correct 96 ms 9920 KB Output is correct
50 Correct 87 ms 11036 KB Output is correct
51 Correct 85 ms 11844 KB Output is correct
52 Correct 91 ms 12812 KB Output is correct
53 Correct 86 ms 13784 KB Output is correct
54 Correct 83 ms 14860 KB Output is correct
55 Correct 78 ms 15708 KB Output is correct
56 Correct 98 ms 16580 KB Output is correct
57 Correct 88 ms 17536 KB Output is correct
58 Correct 89 ms 18500 KB Output is correct
59 Correct 86 ms 18788 KB Output is correct
60 Correct 112 ms 19872 KB Output is correct
61 Correct 86 ms 20620 KB Output is correct
62 Correct 77 ms 21700 KB Output is correct
63 Correct 93 ms 22492 KB Output is correct
64 Correct 87 ms 23660 KB Output is correct
65 Correct 84 ms 24512 KB Output is correct
66 Correct 89 ms 25380 KB Output is correct
67 Correct 80 ms 26400 KB Output is correct
68 Correct 85 ms 27372 KB Output is correct
69 Correct 83 ms 28248 KB Output is correct