Submission #224046

# Submission time Handle Problem Language Result Execution time Memory
224046 2020-04-17T06:07:35 Z tqbfjotld Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
321 ms 135308 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1000000000000000000LL
#define DEBUG false

int pos[205];
int reqt[205];
int n,L;
int memo[205][205][205][2];

int func(int l, int r, int num, bool side){
    if (l==0 && r==0){
        return num==0?0:INF;
    }
    if (l==0){
        if (!side) return memo[l][r][num][side] = INF;
    }
    if (r==0){
        if (side) return memo[l][r][num][side] = INF;
    }
    if (num<=0){
        return side?pos[r-1]:(L-pos[n-l]);
    }
    if (memo[l][r][num][side]!=-1) return memo[l][r][num][side];


    if (side){
        int ans = INF;
        ans = min(ans,func(l,r-1,num,true)+pos[r-1]-pos[r-2]);
        if (DEBUG) printf("%d %d\n",ans,func(l,r-1,num,true));
        ans = min(ans,func(l,r-1,num,false)+pos[r-1]+L-pos[n-l]);
        if (DEBUG) printf("%d\n",ans);
        int t = func(l,r-1,num-1,true);
        if (t+pos[r-1]-pos[r-2]<=reqt[r-1]){
            ans = min(ans,t+pos[r-1]-pos[r-2]);
        }
        if (DEBUG) printf("%d\n",ans);
        t = func(l,r-1,num-1,false);
        if (t+pos[r-1]+L-pos[n-l]<=reqt[r-1]){
            ans = min(ans,t+pos[r-1]+L-pos[n-l]);
        }
        if (DEBUG) printf("%d\n",ans);
        return memo[l][r][num][side] = ans;
    }
    else{
        int ans = INF;
        ans = min(ans,func(l-1,r,num,true)+pos[r-1]+L-pos[n-l]);
        ans = min(ans,func(l-1,r,num,false)+pos[n-l+1]-pos[n-l]);
        int t = func(l-1,r,num-1,true);
        if (t+pos[r-1]+L-pos[n-l]<=reqt[n-l]){
            ans = min(ans,t+pos[r-1]+L-pos[n-l]);
        }
        t = func(l-1,r,num-1,false);
        if (t+pos[n-l+1]-pos[n-l]<=reqt[n-l]){
            ans = min(ans,t+pos[n-l+1]-pos[n-l]);
        }
        return memo[l][r][num][side] = ans;
    }
}

main(){
    scanf("%lld%lld",&n,&L);
    for (int x = 0; x<n; x++){
        scanf("%lld",&pos[x]);
    }
    for (int x = 0; x<n; x++){
        scanf("%lld",&reqt[x]);
    }
    pos[n] = L;
    reqt[n] = INF;
    memset(memo,-1,sizeof(memo));
    int ans = 0;
    for (int x = 0; x<=n; x++){
        for (int t = 0; t<=n; t++){
             //   printf("time for %d to %d, %d stamps, end at right = %d\n",-x,n-x,t,func(x,n-x,t,true));
            if (func(x,n-x,t,true)<INF){

                ans = max(ans,t);
            }
            if (func(x,n-x,t,false)<INF){
                ans = max(ans,t);
            }
        }
    }
    printf("%lld",ans);
}

Compilation message

ho_t3.cpp: In function 'long long int func(long long int, long long int, long long int, bool)':
ho_t3.cpp:31:61: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
         if (DEBUG) printf("%d %d\n",ans,func(l,r-1,num,true));
                                                             ^
ho_t3.cpp:31:61: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long long int' [-Wformat=]
ho_t3.cpp:33:37: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
         if (DEBUG) printf("%d\n",ans);
                                     ^
ho_t3.cpp:38:37: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
         if (DEBUG) printf("%d\n",ans);
                                     ^
ho_t3.cpp:43:37: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
         if (DEBUG) printf("%d\n",ans);
                                     ^
ho_t3.cpp: At global scope:
ho_t3.cpp:62:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&n,&L);
     ~~~~~^~~~~~~~~~~~~~~~~~
ho_t3.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&pos[x]);
         ~~~~~^~~~~~~~~~~~~~~~
ho_t3.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&reqt[x]);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 68 ms 135160 KB Output is correct
2 Correct 67 ms 135160 KB Output is correct
3 Correct 67 ms 135160 KB Output is correct
4 Correct 75 ms 135160 KB Output is correct
5 Correct 67 ms 135160 KB Output is correct
6 Correct 76 ms 135160 KB Output is correct
7 Correct 75 ms 135160 KB Output is correct
8 Correct 68 ms 135160 KB Output is correct
9 Correct 68 ms 135160 KB Output is correct
10 Correct 68 ms 135160 KB Output is correct
11 Correct 67 ms 135160 KB Output is correct
12 Correct 74 ms 135160 KB Output is correct
13 Correct 75 ms 135160 KB Output is correct
14 Correct 74 ms 135160 KB Output is correct
15 Correct 75 ms 135160 KB Output is correct
16 Correct 69 ms 135160 KB Output is correct
17 Correct 68 ms 135228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 135160 KB Output is correct
2 Correct 67 ms 135160 KB Output is correct
3 Correct 67 ms 135160 KB Output is correct
4 Correct 75 ms 135160 KB Output is correct
5 Correct 67 ms 135160 KB Output is correct
6 Correct 76 ms 135160 KB Output is correct
7 Correct 75 ms 135160 KB Output is correct
8 Correct 68 ms 135160 KB Output is correct
9 Correct 68 ms 135160 KB Output is correct
10 Correct 68 ms 135160 KB Output is correct
11 Correct 67 ms 135160 KB Output is correct
12 Correct 74 ms 135160 KB Output is correct
13 Correct 75 ms 135160 KB Output is correct
14 Correct 74 ms 135160 KB Output is correct
15 Correct 75 ms 135160 KB Output is correct
16 Correct 69 ms 135160 KB Output is correct
17 Correct 68 ms 135228 KB Output is correct
18 Correct 72 ms 135160 KB Output is correct
19 Correct 67 ms 135160 KB Output is correct
20 Correct 67 ms 135192 KB Output is correct
21 Correct 66 ms 135160 KB Output is correct
22 Correct 74 ms 135160 KB Output is correct
23 Correct 66 ms 135160 KB Output is correct
24 Correct 65 ms 135164 KB Output is correct
25 Correct 65 ms 135160 KB Output is correct
26 Correct 70 ms 135160 KB Output is correct
27 Correct 74 ms 135160 KB Output is correct
28 Correct 74 ms 135152 KB Output is correct
29 Correct 70 ms 135160 KB Output is correct
30 Correct 68 ms 135160 KB Output is correct
31 Correct 68 ms 135188 KB Output is correct
32 Correct 67 ms 135160 KB Output is correct
33 Correct 65 ms 135160 KB Output is correct
34 Correct 69 ms 135288 KB Output is correct
35 Correct 67 ms 135160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 135160 KB Output is correct
2 Correct 67 ms 135160 KB Output is correct
3 Correct 67 ms 135160 KB Output is correct
4 Correct 75 ms 135160 KB Output is correct
5 Correct 67 ms 135160 KB Output is correct
6 Correct 76 ms 135160 KB Output is correct
7 Correct 75 ms 135160 KB Output is correct
8 Correct 68 ms 135160 KB Output is correct
9 Correct 68 ms 135160 KB Output is correct
10 Correct 68 ms 135160 KB Output is correct
11 Correct 67 ms 135160 KB Output is correct
12 Correct 74 ms 135160 KB Output is correct
13 Correct 75 ms 135160 KB Output is correct
14 Correct 74 ms 135160 KB Output is correct
15 Correct 75 ms 135160 KB Output is correct
16 Correct 69 ms 135160 KB Output is correct
17 Correct 68 ms 135228 KB Output is correct
18 Correct 232 ms 135288 KB Output is correct
19 Correct 152 ms 135288 KB Output is correct
20 Correct 106 ms 135160 KB Output is correct
21 Correct 145 ms 135252 KB Output is correct
22 Correct 173 ms 135160 KB Output is correct
23 Correct 91 ms 135160 KB Output is correct
24 Correct 89 ms 135164 KB Output is correct
25 Correct 87 ms 135160 KB Output is correct
26 Correct 72 ms 135160 KB Output is correct
27 Correct 87 ms 135160 KB Output is correct
28 Correct 94 ms 135160 KB Output is correct
29 Correct 91 ms 135160 KB Output is correct
30 Correct 81 ms 135160 KB Output is correct
31 Correct 89 ms 135160 KB Output is correct
32 Correct 76 ms 135160 KB Output is correct
33 Correct 98 ms 135208 KB Output is correct
34 Correct 74 ms 135184 KB Output is correct
35 Correct 87 ms 135164 KB Output is correct
36 Correct 75 ms 135160 KB Output is correct
37 Correct 92 ms 135160 KB Output is correct
38 Correct 82 ms 135160 KB Output is correct
39 Correct 93 ms 135160 KB Output is correct
40 Correct 79 ms 135288 KB Output is correct
41 Correct 289 ms 135160 KB Output is correct
42 Correct 179 ms 135160 KB Output is correct
43 Correct 290 ms 135160 KB Output is correct
44 Correct 185 ms 135160 KB Output is correct
45 Correct 315 ms 135160 KB Output is correct
46 Correct 185 ms 135288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 135160 KB Output is correct
2 Correct 67 ms 135160 KB Output is correct
3 Correct 67 ms 135160 KB Output is correct
4 Correct 75 ms 135160 KB Output is correct
5 Correct 67 ms 135160 KB Output is correct
6 Correct 76 ms 135160 KB Output is correct
7 Correct 75 ms 135160 KB Output is correct
8 Correct 68 ms 135160 KB Output is correct
9 Correct 68 ms 135160 KB Output is correct
10 Correct 68 ms 135160 KB Output is correct
11 Correct 67 ms 135160 KB Output is correct
12 Correct 74 ms 135160 KB Output is correct
13 Correct 75 ms 135160 KB Output is correct
14 Correct 74 ms 135160 KB Output is correct
15 Correct 75 ms 135160 KB Output is correct
16 Correct 69 ms 135160 KB Output is correct
17 Correct 68 ms 135228 KB Output is correct
18 Correct 72 ms 135160 KB Output is correct
19 Correct 67 ms 135160 KB Output is correct
20 Correct 67 ms 135192 KB Output is correct
21 Correct 66 ms 135160 KB Output is correct
22 Correct 74 ms 135160 KB Output is correct
23 Correct 66 ms 135160 KB Output is correct
24 Correct 65 ms 135164 KB Output is correct
25 Correct 65 ms 135160 KB Output is correct
26 Correct 70 ms 135160 KB Output is correct
27 Correct 74 ms 135160 KB Output is correct
28 Correct 74 ms 135152 KB Output is correct
29 Correct 70 ms 135160 KB Output is correct
30 Correct 68 ms 135160 KB Output is correct
31 Correct 68 ms 135188 KB Output is correct
32 Correct 67 ms 135160 KB Output is correct
33 Correct 65 ms 135160 KB Output is correct
34 Correct 69 ms 135288 KB Output is correct
35 Correct 67 ms 135160 KB Output is correct
36 Correct 232 ms 135288 KB Output is correct
37 Correct 152 ms 135288 KB Output is correct
38 Correct 106 ms 135160 KB Output is correct
39 Correct 145 ms 135252 KB Output is correct
40 Correct 173 ms 135160 KB Output is correct
41 Correct 91 ms 135160 KB Output is correct
42 Correct 89 ms 135164 KB Output is correct
43 Correct 87 ms 135160 KB Output is correct
44 Correct 72 ms 135160 KB Output is correct
45 Correct 87 ms 135160 KB Output is correct
46 Correct 94 ms 135160 KB Output is correct
47 Correct 91 ms 135160 KB Output is correct
48 Correct 81 ms 135160 KB Output is correct
49 Correct 89 ms 135160 KB Output is correct
50 Correct 76 ms 135160 KB Output is correct
51 Correct 98 ms 135208 KB Output is correct
52 Correct 74 ms 135184 KB Output is correct
53 Correct 87 ms 135164 KB Output is correct
54 Correct 75 ms 135160 KB Output is correct
55 Correct 92 ms 135160 KB Output is correct
56 Correct 82 ms 135160 KB Output is correct
57 Correct 93 ms 135160 KB Output is correct
58 Correct 79 ms 135288 KB Output is correct
59 Correct 289 ms 135160 KB Output is correct
60 Correct 179 ms 135160 KB Output is correct
61 Correct 290 ms 135160 KB Output is correct
62 Correct 185 ms 135160 KB Output is correct
63 Correct 315 ms 135160 KB Output is correct
64 Correct 185 ms 135288 KB Output is correct
65 Correct 257 ms 135288 KB Output is correct
66 Correct 268 ms 135288 KB Output is correct
67 Correct 239 ms 135160 KB Output is correct
68 Correct 206 ms 135292 KB Output is correct
69 Correct 277 ms 135160 KB Output is correct
70 Correct 232 ms 135288 KB Output is correct
71 Correct 260 ms 135160 KB Output is correct
72 Correct 237 ms 135160 KB Output is correct
73 Correct 237 ms 135160 KB Output is correct
74 Correct 204 ms 135288 KB Output is correct
75 Correct 230 ms 135160 KB Output is correct
76 Correct 266 ms 135160 KB Output is correct
77 Correct 259 ms 135164 KB Output is correct
78 Correct 203 ms 135160 KB Output is correct
79 Correct 215 ms 135288 KB Output is correct
80 Correct 256 ms 135164 KB Output is correct
81 Correct 211 ms 135288 KB Output is correct
82 Correct 232 ms 135288 KB Output is correct
83 Correct 285 ms 135160 KB Output is correct
84 Correct 239 ms 135288 KB Output is correct
85 Correct 264 ms 135160 KB Output is correct
86 Correct 253 ms 135288 KB Output is correct
87 Correct 238 ms 135160 KB Output is correct
88 Correct 295 ms 135160 KB Output is correct
89 Correct 292 ms 135288 KB Output is correct
90 Correct 226 ms 135288 KB Output is correct
91 Correct 298 ms 135288 KB Output is correct
92 Correct 321 ms 135308 KB Output is correct
93 Correct 278 ms 135160 KB Output is correct