Submission #126313

# Submission time Handle Problem Language Result Execution time Memory
126313 2019-07-07T11:38:05 Z choikiwon Sparklers (JOI17_sparklers) C++17
50 / 100
450 ms 6592 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MN = 100010;

void print(vector<ll> &a) {
    for(int i = 0; i < a.size(); i++) {
        cout << a[i] << ' ';
    }
    cout << endl;
}

int N, K, T;
int X[MN];
vector<ll> le, ri, psum1, psum2;

int cc[1010][1010];
int dp(int a, int b) {
    if(a == le.size() && b == ri.size()) return 1;
    int &ret = cc[a][b];
    if(ret != -1) return ret;

    ll rem = (a? psum1[a - 1] : 0) + (b? psum2[b - 1] : 0);

    ret = 0;
    if(a < le.size() && rem + le[a] >= 0) ret |= dp(a + 1, b);
    if(b < ri.size() && rem + ri[b] >= 0) ret |= dp(a, b + 1);
    return ret;
}

bool check(int x) {
    le.clear();
    ri.clear();
    for(int i = 0; i < K; i++) {
        ll d = 1LL * T * x - (X[i + 1] - X[i]);
        le.push_back(d);
    }
    reverse(le.begin(), le.end());

    for(int i = K; i < N - 1; i++) {
        ll d = 1LL * T * x - (X[i + 1] - X[i]);
        ri.push_back(d);
    }

    psum1.clear();
    psum2.clear();
    psum1.resize(le.size());
    psum2.resize(ri.size());

    for(int i = 0; i < le.size(); i++) {
        psum1[i] = le[i];
        if(i) psum1[i] += psum1[i - 1];
    }
    for(int i = 0; i < ri.size(); i++) {
        psum2[i] = ri[i];
        if(i) psum2[i] += psum2[i - 1];
    }
    memset(cc, -1, sizeof(cc));
    return dp(0, 0);
}

int main() {
    scanf("%d %d %d", &N, &K, &T);
    K--;

    for(int i = 0; i < N; i++) {
        scanf("%d", &X[i]);
    }

    int s = 0, e = 1e9 / T + 1, p = -1;
    while(s <= e) {
        int m = (s + e)>>1;

        if(check(2 * m)) {
            p = m;
            e = m - 1;
        }
        else s = m + 1;
    }
    printf("%d", p);
}

Compilation message

sparklers.cpp: In function 'void print(std::vector<long long int>&)':
sparklers.cpp:9:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < a.size(); i++) {
                    ~~^~~~~~~~~~
sparklers.cpp: In function 'int dp(int, int)':
sparklers.cpp:21:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(a == le.size() && b == ri.size()) return 1;
        ~~^~~~~~~~~~~~
sparklers.cpp:21:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(a == le.size() && b == ri.size()) return 1;
                          ~~^~~~~~~~~~~~
sparklers.cpp:28:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(a < le.size() && rem + le[a] >= 0) ret |= dp(a + 1, b);
        ~~^~~~~~~~~~~
sparklers.cpp:29:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(b < ri.size() && rem + ri[b] >= 0) ret |= dp(a, b + 1);
        ~~^~~~~~~~~~~
sparklers.cpp: In function 'bool check(int)':
sparklers.cpp:52:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < le.size(); i++) {
                    ~~^~~~~~~~~~~
sparklers.cpp:56:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < ri.size(); i++) {
                    ~~^~~~~~~~~~~
sparklers.cpp: In function 'int main()':
sparklers.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &N, &K, &T);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &X[i]);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4472 KB Output is correct
2 Correct 11 ms 4344 KB Output is correct
3 Correct 11 ms 4344 KB Output is correct
4 Correct 11 ms 4344 KB Output is correct
5 Correct 11 ms 4344 KB Output is correct
6 Correct 11 ms 4340 KB Output is correct
7 Correct 11 ms 4344 KB Output is correct
8 Correct 11 ms 4344 KB Output is correct
9 Correct 12 ms 4360 KB Output is correct
10 Correct 11 ms 4344 KB Output is correct
11 Correct 11 ms 4344 KB Output is correct
12 Correct 13 ms 4344 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 11 ms 4344 KB Output is correct
15 Correct 11 ms 4344 KB Output is correct
16 Correct 11 ms 4344 KB Output is correct
17 Correct 11 ms 4344 KB Output is correct
18 Correct 11 ms 4344 KB Output is correct
19 Correct 11 ms 4344 KB Output is correct
20 Correct 12 ms 4344 KB Output is correct
21 Correct 11 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4472 KB Output is correct
2 Correct 11 ms 4344 KB Output is correct
3 Correct 11 ms 4344 KB Output is correct
4 Correct 11 ms 4344 KB Output is correct
5 Correct 11 ms 4344 KB Output is correct
6 Correct 11 ms 4340 KB Output is correct
7 Correct 11 ms 4344 KB Output is correct
8 Correct 11 ms 4344 KB Output is correct
9 Correct 12 ms 4360 KB Output is correct
10 Correct 11 ms 4344 KB Output is correct
11 Correct 11 ms 4344 KB Output is correct
12 Correct 13 ms 4344 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 11 ms 4344 KB Output is correct
15 Correct 11 ms 4344 KB Output is correct
16 Correct 11 ms 4344 KB Output is correct
17 Correct 11 ms 4344 KB Output is correct
18 Correct 11 ms 4344 KB Output is correct
19 Correct 11 ms 4344 KB Output is correct
20 Correct 12 ms 4344 KB Output is correct
21 Correct 11 ms 4344 KB Output is correct
22 Correct 42 ms 4344 KB Output is correct
23 Correct 32 ms 4344 KB Output is correct
24 Correct 20 ms 4344 KB Output is correct
25 Correct 16 ms 4344 KB Output is correct
26 Correct 51 ms 4472 KB Output is correct
27 Correct 57 ms 4344 KB Output is correct
28 Correct 79 ms 4448 KB Output is correct
29 Correct 84 ms 4344 KB Output is correct
30 Correct 58 ms 4348 KB Output is correct
31 Correct 68 ms 4472 KB Output is correct
32 Correct 80 ms 4472 KB Output is correct
33 Correct 91 ms 4344 KB Output is correct
34 Correct 49 ms 4472 KB Output is correct
35 Correct 85 ms 4344 KB Output is correct
36 Correct 39 ms 4472 KB Output is correct
37 Correct 35 ms 4344 KB Output is correct
38 Correct 80 ms 4472 KB Output is correct
39 Correct 28 ms 4344 KB Output is correct
40 Correct 113 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4472 KB Output is correct
2 Correct 11 ms 4344 KB Output is correct
3 Correct 11 ms 4344 KB Output is correct
4 Correct 11 ms 4344 KB Output is correct
5 Correct 11 ms 4344 KB Output is correct
6 Correct 11 ms 4340 KB Output is correct
7 Correct 11 ms 4344 KB Output is correct
8 Correct 11 ms 4344 KB Output is correct
9 Correct 12 ms 4360 KB Output is correct
10 Correct 11 ms 4344 KB Output is correct
11 Correct 11 ms 4344 KB Output is correct
12 Correct 13 ms 4344 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 11 ms 4344 KB Output is correct
15 Correct 11 ms 4344 KB Output is correct
16 Correct 11 ms 4344 KB Output is correct
17 Correct 11 ms 4344 KB Output is correct
18 Correct 11 ms 4344 KB Output is correct
19 Correct 11 ms 4344 KB Output is correct
20 Correct 12 ms 4344 KB Output is correct
21 Correct 11 ms 4344 KB Output is correct
22 Correct 42 ms 4344 KB Output is correct
23 Correct 32 ms 4344 KB Output is correct
24 Correct 20 ms 4344 KB Output is correct
25 Correct 16 ms 4344 KB Output is correct
26 Correct 51 ms 4472 KB Output is correct
27 Correct 57 ms 4344 KB Output is correct
28 Correct 79 ms 4448 KB Output is correct
29 Correct 84 ms 4344 KB Output is correct
30 Correct 58 ms 4348 KB Output is correct
31 Correct 68 ms 4472 KB Output is correct
32 Correct 80 ms 4472 KB Output is correct
33 Correct 91 ms 4344 KB Output is correct
34 Correct 49 ms 4472 KB Output is correct
35 Correct 85 ms 4344 KB Output is correct
36 Correct 39 ms 4472 KB Output is correct
37 Correct 35 ms 4344 KB Output is correct
38 Correct 80 ms 4472 KB Output is correct
39 Correct 28 ms 4344 KB Output is correct
40 Correct 113 ms 4444 KB Output is correct
41 Incorrect 450 ms 6592 KB Output isn't correct
42 Halted 0 ms 0 KB -