Submission #428857

# Submission time Handle Problem Language Result Execution time Memory
428857 2021-06-15T14:58:14 Z tqbfjotld Sparklers (JOI17_sparklers) C++14
50 / 100
870 ms 21280 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

pair<int,int> memo[1005][1005];
int arr[100005];

int K,T,N;
int M;

pair<int,int> func(int a, int b){
    if (a==b) return a==K?make_pair(arr[K]-M*T,arr[K]+M*T):make_pair(999999999999999999LL,-999999999999999999LL);
    if (memo[a][b]!=make_pair(-1LL,-1LL)) return memo[a][b];
   // printf("%lld %lld, %lld\n",a,b,K);
    if (b<K || a>K) return {999999999999999999LL,-999999999999999999LL};
    auto opt1 = func(a,b-1);
    auto opt2 = func(a+1,b);
   //if (opt1.first<0) opt1.first = 0;
    //if (opt2.first<0) opt2.first = 0;

       // printf("opt1 = %lld %lld, \n",opt1);
       // printf("optw = %lld %lld, ab = %lld %lld\n",opt2,a,b);
    if (opt1.second<opt1.first){
        if (opt2.second<opt2.first) return memo[a][b] = {999999999999999999LL,-999999999999999999LL};
        int sz = (b-a);
        if (sz*T*M+arr[a]<opt2.first) return memo[a][b] = {999999999999999999LL,-999999999999999999LL};
        return memo[a][b] = {opt2.first-T*M,(sz+1)*T*M+arr[a]};
    }
    else {
            int sz = (b-a);
            if (-sz*T*M+arr[b]>opt1.second) return memo[a][b] = {999999999999999999LL,-999999999999999999LL};
            return memo[a][b] = {-(sz+1)*T*M+arr[b],opt1.second+T*M};

    }
}

bool test(int val){
    M = val;
    memset(memo,-1,sizeof(memo));
    auto res = func(0,N-1);
    //printf("val = %lld, res = %lld %lld\n",val,res);
    return res.second>=res.first;
}

main(){
    long long n,k,t;
    scanf("%lld%lld%lld",&n,&k,&t);
    N = n; K = k; T = t;
    K--;
    for (int x = 0; x<N; x++){
        long long t;
        scanf("%lld",&t);
        arr[x] = t;
    }
    long long r = 1000000000LL/T+1;
    int l = -1LL;
    while (l+1<r){
        int mid = (l+r)/2;
        if (test(mid)){
            r = mid;
        }
        else l = mid;
    }
    printf("%lld\n",r);
}

Compilation message

sparklers.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main(){
      | ^~~~
sparklers.cpp: In function 'int main()':
sparklers.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     scanf("%lld%lld%lld",&n,&k,&t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         scanf("%lld",&t);
      |         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 64 ms 16076 KB Output is correct
2 Correct 64 ms 16076 KB Output is correct
3 Correct 63 ms 16096 KB Output is correct
4 Correct 61 ms 16092 KB Output is correct
5 Correct 66 ms 16076 KB Output is correct
6 Correct 62 ms 16076 KB Output is correct
7 Correct 66 ms 16088 KB Output is correct
8 Correct 60 ms 16076 KB Output is correct
9 Correct 63 ms 16196 KB Output is correct
10 Correct 66 ms 16076 KB Output is correct
11 Correct 61 ms 16092 KB Output is correct
12 Correct 63 ms 16080 KB Output is correct
13 Correct 64 ms 16108 KB Output is correct
14 Correct 62 ms 16104 KB Output is correct
15 Correct 68 ms 16092 KB Output is correct
16 Correct 63 ms 16076 KB Output is correct
17 Correct 62 ms 16076 KB Output is correct
18 Correct 64 ms 16076 KB Output is correct
19 Correct 63 ms 16088 KB Output is correct
20 Correct 60 ms 16076 KB Output is correct
21 Correct 62 ms 16076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 16076 KB Output is correct
2 Correct 64 ms 16076 KB Output is correct
3 Correct 63 ms 16096 KB Output is correct
4 Correct 61 ms 16092 KB Output is correct
5 Correct 66 ms 16076 KB Output is correct
6 Correct 62 ms 16076 KB Output is correct
7 Correct 66 ms 16088 KB Output is correct
8 Correct 60 ms 16076 KB Output is correct
9 Correct 63 ms 16196 KB Output is correct
10 Correct 66 ms 16076 KB Output is correct
11 Correct 61 ms 16092 KB Output is correct
12 Correct 63 ms 16080 KB Output is correct
13 Correct 64 ms 16108 KB Output is correct
14 Correct 62 ms 16104 KB Output is correct
15 Correct 68 ms 16092 KB Output is correct
16 Correct 63 ms 16076 KB Output is correct
17 Correct 62 ms 16076 KB Output is correct
18 Correct 64 ms 16076 KB Output is correct
19 Correct 63 ms 16088 KB Output is correct
20 Correct 60 ms 16076 KB Output is correct
21 Correct 62 ms 16076 KB Output is correct
22 Correct 110 ms 16136 KB Output is correct
23 Correct 93 ms 16240 KB Output is correct
24 Correct 79 ms 16128 KB Output is correct
25 Correct 70 ms 16144 KB Output is correct
26 Correct 136 ms 16144 KB Output is correct
27 Correct 128 ms 16144 KB Output is correct
28 Correct 166 ms 16140 KB Output is correct
29 Correct 174 ms 16144 KB Output is correct
30 Correct 155 ms 16140 KB Output is correct
31 Correct 147 ms 16140 KB Output is correct
32 Correct 167 ms 16140 KB Output is correct
33 Correct 169 ms 16156 KB Output is correct
34 Correct 129 ms 16200 KB Output is correct
35 Correct 159 ms 16140 KB Output is correct
36 Correct 121 ms 16144 KB Output is correct
37 Correct 119 ms 16076 KB Output is correct
38 Correct 154 ms 16148 KB Output is correct
39 Correct 93 ms 16140 KB Output is correct
40 Correct 165 ms 16144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 16076 KB Output is correct
2 Correct 64 ms 16076 KB Output is correct
3 Correct 63 ms 16096 KB Output is correct
4 Correct 61 ms 16092 KB Output is correct
5 Correct 66 ms 16076 KB Output is correct
6 Correct 62 ms 16076 KB Output is correct
7 Correct 66 ms 16088 KB Output is correct
8 Correct 60 ms 16076 KB Output is correct
9 Correct 63 ms 16196 KB Output is correct
10 Correct 66 ms 16076 KB Output is correct
11 Correct 61 ms 16092 KB Output is correct
12 Correct 63 ms 16080 KB Output is correct
13 Correct 64 ms 16108 KB Output is correct
14 Correct 62 ms 16104 KB Output is correct
15 Correct 68 ms 16092 KB Output is correct
16 Correct 63 ms 16076 KB Output is correct
17 Correct 62 ms 16076 KB Output is correct
18 Correct 64 ms 16076 KB Output is correct
19 Correct 63 ms 16088 KB Output is correct
20 Correct 60 ms 16076 KB Output is correct
21 Correct 62 ms 16076 KB Output is correct
22 Correct 110 ms 16136 KB Output is correct
23 Correct 93 ms 16240 KB Output is correct
24 Correct 79 ms 16128 KB Output is correct
25 Correct 70 ms 16144 KB Output is correct
26 Correct 136 ms 16144 KB Output is correct
27 Correct 128 ms 16144 KB Output is correct
28 Correct 166 ms 16140 KB Output is correct
29 Correct 174 ms 16144 KB Output is correct
30 Correct 155 ms 16140 KB Output is correct
31 Correct 147 ms 16140 KB Output is correct
32 Correct 167 ms 16140 KB Output is correct
33 Correct 169 ms 16156 KB Output is correct
34 Correct 129 ms 16200 KB Output is correct
35 Correct 159 ms 16140 KB Output is correct
36 Correct 121 ms 16144 KB Output is correct
37 Correct 119 ms 16076 KB Output is correct
38 Correct 154 ms 16148 KB Output is correct
39 Correct 93 ms 16140 KB Output is correct
40 Correct 165 ms 16144 KB Output is correct
41 Correct 710 ms 17396 KB Output is correct
42 Correct 171 ms 16204 KB Output is correct
43 Correct 683 ms 16552 KB Output is correct
44 Incorrect 870 ms 21280 KB Output isn't correct
45 Halted 0 ms 0 KB -