Submission #224205

# Submission time Handle Problem Language Result Execution time Memory
224205 2020-04-17T12:51:18 Z dantoh000 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
282 ms 135416 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const ll INF = 1000000000000000000;
int n,l;
int p[205], t[205];
ll mem[2][205][205][205];
///min time to reach state:
///[0,x[i]] U [x[j],L] visited;
///currently at x[i]/x[j] depending on d
///k stamps collected;
ll dp(int d, int i, int j, int k){
    if (mem[d][i][j][k] != -1) return mem[d][i][j][k];
    ll res = INF;
    ///try not taking anything
    if (d == 0 && i != 0){
        res = min(dp(0,i-1,j,k)+p[i]-p[i-1],
                  dp(1,i-1,j,k)+l-p[j]+p[i]);
    }
    if (d == 1 && j != n+1){
        res = min(dp(0,i,j+1,k)+l-p[j]+p[i],
                  dp(1,i,j+1,k)+p[j+1]-p[j]);
    }
    ///take something
    if (k){
        ll T = INF;
        if (d == 0 && i != 0){
            T = dp(0,i-1,j,k-1)+p[i]-p[i-1];
            //printf("if from %d to %d clock, take %lld+%d\n",i-1,i,dp(0,i-1,j,k-1),p[i]-p[i-1]);
            if (T <= t[i]) res = min(res,T);
            T = dp(1,i-1,j,k-1)+l-p[j]+p[i];
            //printf("if from %d to %d clock, take %lld+%d\n",j,i,dp(1,i-1,j,k-1),l-p[j]+p[i]);
            if (T <= t[i]) res = min(res,T);
        }
        if (d == 1 && j != n+1){
            T = dp(0,i,j+1,k-1)+l-p[j]+p[i];
            //printf("if from %d to %d anticlock, take %lld+%d\n",i,j,dp(0,i,j+1,k-1),l-p[j]+p[i]);
            if (T <= t[j]) res = min(res,T);
            T = dp(1,i,j+1,k-1)+p[j+1]-p[j];
            //printf("if from %d to %d anticlock, take %lld+%d\n",j+1,j,dp(1,i,j+1,k-1),p[j+1]-p[j]);
            if (T <= t[j]) res = min(res,T);
        }
    }
    //printf("%d %d %d %d %lld\n",d,i,j,k,res);
    return mem[d][i][j][k] = res;
}
int main(){
    scanf("%d%d",&n,&l);
    for (int i = 1; i <= n; i++){
        scanf("%d",&p[i]);
    }
    p[n+1] = l;
    for (int i = 1; i <= n; i++){
        scanf("%d",&t[i]);
    }
    memset(mem,-1,sizeof(mem));
    mem[0][0][n+1][0] = mem[1][0][n+1][0] = 0;
    int ans = 0;
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= n; j++){
            if (dp(0,i,i+1,j) < INF || dp(1,i,i+1,j) < INF) {
                //printf("%d %d %d\n",i,i+1,j);
                ans = max(ans,j);
            }
        }
    }
    printf("%d ",ans);



}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&l);
     ~~~~~^~~~~~~~~~~~~~
ho_t3.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&p[i]);
         ~~~~~^~~~~~~~~~~~
ho_t3.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&t[i]);
         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 68 ms 135032 KB Output is correct
2 Correct 79 ms 135160 KB Output is correct
3 Correct 77 ms 135164 KB Output is correct
4 Correct 67 ms 135160 KB Output is correct
5 Correct 69 ms 135160 KB Output is correct
6 Correct 67 ms 135160 KB Output is correct
7 Correct 69 ms 135160 KB Output is correct
8 Correct 73 ms 135160 KB Output is correct
9 Correct 73 ms 135208 KB Output is correct
10 Correct 66 ms 135160 KB Output is correct
11 Correct 76 ms 135160 KB Output is correct
12 Correct 68 ms 135160 KB Output is correct
13 Correct 67 ms 135160 KB Output is correct
14 Correct 70 ms 135160 KB Output is correct
15 Correct 68 ms 135160 KB Output is correct
16 Correct 68 ms 135232 KB Output is correct
17 Correct 69 ms 135160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 135032 KB Output is correct
2 Correct 79 ms 135160 KB Output is correct
3 Correct 77 ms 135164 KB Output is correct
4 Correct 67 ms 135160 KB Output is correct
5 Correct 69 ms 135160 KB Output is correct
6 Correct 67 ms 135160 KB Output is correct
7 Correct 69 ms 135160 KB Output is correct
8 Correct 73 ms 135160 KB Output is correct
9 Correct 73 ms 135208 KB Output is correct
10 Correct 66 ms 135160 KB Output is correct
11 Correct 76 ms 135160 KB Output is correct
12 Correct 68 ms 135160 KB Output is correct
13 Correct 67 ms 135160 KB Output is correct
14 Correct 70 ms 135160 KB Output is correct
15 Correct 68 ms 135160 KB Output is correct
16 Correct 68 ms 135232 KB Output is correct
17 Correct 69 ms 135160 KB Output is correct
18 Correct 71 ms 135160 KB Output is correct
19 Correct 77 ms 135160 KB Output is correct
20 Correct 67 ms 135160 KB Output is correct
21 Correct 72 ms 135160 KB Output is correct
22 Correct 67 ms 135160 KB Output is correct
23 Correct 67 ms 135160 KB Output is correct
24 Correct 68 ms 135160 KB Output is correct
25 Correct 70 ms 135160 KB Output is correct
26 Correct 68 ms 135160 KB Output is correct
27 Correct 66 ms 135160 KB Output is correct
28 Correct 70 ms 135160 KB Output is correct
29 Correct 67 ms 135160 KB Output is correct
30 Correct 69 ms 135160 KB Output is correct
31 Correct 68 ms 135164 KB Output is correct
32 Correct 68 ms 135160 KB Output is correct
33 Correct 70 ms 135160 KB Output is correct
34 Correct 67 ms 135160 KB Output is correct
35 Correct 68 ms 135160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 135032 KB Output is correct
2 Correct 79 ms 135160 KB Output is correct
3 Correct 77 ms 135164 KB Output is correct
4 Correct 67 ms 135160 KB Output is correct
5 Correct 69 ms 135160 KB Output is correct
6 Correct 67 ms 135160 KB Output is correct
7 Correct 69 ms 135160 KB Output is correct
8 Correct 73 ms 135160 KB Output is correct
9 Correct 73 ms 135208 KB Output is correct
10 Correct 66 ms 135160 KB Output is correct
11 Correct 76 ms 135160 KB Output is correct
12 Correct 68 ms 135160 KB Output is correct
13 Correct 67 ms 135160 KB Output is correct
14 Correct 70 ms 135160 KB Output is correct
15 Correct 68 ms 135160 KB Output is correct
16 Correct 68 ms 135232 KB Output is correct
17 Correct 69 ms 135160 KB Output is correct
18 Correct 215 ms 135288 KB Output is correct
19 Correct 139 ms 135204 KB Output is correct
20 Correct 102 ms 135288 KB Output is correct
21 Correct 137 ms 135292 KB Output is correct
22 Correct 166 ms 135304 KB Output is correct
23 Correct 90 ms 135160 KB Output is correct
24 Correct 81 ms 135160 KB Output is correct
25 Correct 92 ms 135288 KB Output is correct
26 Correct 73 ms 135160 KB Output is correct
27 Correct 95 ms 135160 KB Output is correct
28 Correct 81 ms 135160 KB Output is correct
29 Correct 91 ms 135244 KB Output is correct
30 Correct 83 ms 135160 KB Output is correct
31 Correct 94 ms 135288 KB Output is correct
32 Correct 76 ms 135160 KB Output is correct
33 Correct 89 ms 135160 KB Output is correct
34 Correct 75 ms 135192 KB Output is correct
35 Correct 88 ms 135160 KB Output is correct
36 Correct 74 ms 135160 KB Output is correct
37 Correct 86 ms 135244 KB Output is correct
38 Correct 75 ms 135160 KB Output is correct
39 Correct 98 ms 135160 KB Output is correct
40 Correct 86 ms 135136 KB Output is correct
41 Correct 271 ms 135288 KB Output is correct
42 Correct 166 ms 135160 KB Output is correct
43 Correct 277 ms 135288 KB Output is correct
44 Correct 163 ms 135288 KB Output is correct
45 Correct 273 ms 135160 KB Output is correct
46 Correct 166 ms 135160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 135032 KB Output is correct
2 Correct 79 ms 135160 KB Output is correct
3 Correct 77 ms 135164 KB Output is correct
4 Correct 67 ms 135160 KB Output is correct
5 Correct 69 ms 135160 KB Output is correct
6 Correct 67 ms 135160 KB Output is correct
7 Correct 69 ms 135160 KB Output is correct
8 Correct 73 ms 135160 KB Output is correct
9 Correct 73 ms 135208 KB Output is correct
10 Correct 66 ms 135160 KB Output is correct
11 Correct 76 ms 135160 KB Output is correct
12 Correct 68 ms 135160 KB Output is correct
13 Correct 67 ms 135160 KB Output is correct
14 Correct 70 ms 135160 KB Output is correct
15 Correct 68 ms 135160 KB Output is correct
16 Correct 68 ms 135232 KB Output is correct
17 Correct 69 ms 135160 KB Output is correct
18 Correct 71 ms 135160 KB Output is correct
19 Correct 77 ms 135160 KB Output is correct
20 Correct 67 ms 135160 KB Output is correct
21 Correct 72 ms 135160 KB Output is correct
22 Correct 67 ms 135160 KB Output is correct
23 Correct 67 ms 135160 KB Output is correct
24 Correct 68 ms 135160 KB Output is correct
25 Correct 70 ms 135160 KB Output is correct
26 Correct 68 ms 135160 KB Output is correct
27 Correct 66 ms 135160 KB Output is correct
28 Correct 70 ms 135160 KB Output is correct
29 Correct 67 ms 135160 KB Output is correct
30 Correct 69 ms 135160 KB Output is correct
31 Correct 68 ms 135164 KB Output is correct
32 Correct 68 ms 135160 KB Output is correct
33 Correct 70 ms 135160 KB Output is correct
34 Correct 67 ms 135160 KB Output is correct
35 Correct 68 ms 135160 KB Output is correct
36 Correct 215 ms 135288 KB Output is correct
37 Correct 139 ms 135204 KB Output is correct
38 Correct 102 ms 135288 KB Output is correct
39 Correct 137 ms 135292 KB Output is correct
40 Correct 166 ms 135304 KB Output is correct
41 Correct 90 ms 135160 KB Output is correct
42 Correct 81 ms 135160 KB Output is correct
43 Correct 92 ms 135288 KB Output is correct
44 Correct 73 ms 135160 KB Output is correct
45 Correct 95 ms 135160 KB Output is correct
46 Correct 81 ms 135160 KB Output is correct
47 Correct 91 ms 135244 KB Output is correct
48 Correct 83 ms 135160 KB Output is correct
49 Correct 94 ms 135288 KB Output is correct
50 Correct 76 ms 135160 KB Output is correct
51 Correct 89 ms 135160 KB Output is correct
52 Correct 75 ms 135192 KB Output is correct
53 Correct 88 ms 135160 KB Output is correct
54 Correct 74 ms 135160 KB Output is correct
55 Correct 86 ms 135244 KB Output is correct
56 Correct 75 ms 135160 KB Output is correct
57 Correct 98 ms 135160 KB Output is correct
58 Correct 86 ms 135136 KB Output is correct
59 Correct 271 ms 135288 KB Output is correct
60 Correct 166 ms 135160 KB Output is correct
61 Correct 277 ms 135288 KB Output is correct
62 Correct 163 ms 135288 KB Output is correct
63 Correct 273 ms 135160 KB Output is correct
64 Correct 166 ms 135160 KB Output is correct
65 Correct 251 ms 135288 KB Output is correct
66 Correct 221 ms 135160 KB Output is correct
67 Correct 227 ms 135288 KB Output is correct
68 Correct 193 ms 135288 KB Output is correct
69 Correct 241 ms 135160 KB Output is correct
70 Correct 227 ms 135416 KB Output is correct
71 Correct 235 ms 135288 KB Output is correct
72 Correct 238 ms 135160 KB Output is correct
73 Correct 202 ms 135288 KB Output is correct
74 Correct 207 ms 135160 KB Output is correct
75 Correct 213 ms 135160 KB Output is correct
76 Correct 260 ms 135160 KB Output is correct
77 Correct 255 ms 135288 KB Output is correct
78 Correct 199 ms 135288 KB Output is correct
79 Correct 201 ms 135160 KB Output is correct
80 Correct 264 ms 135160 KB Output is correct
81 Correct 203 ms 135160 KB Output is correct
82 Correct 211 ms 135160 KB Output is correct
83 Correct 278 ms 135416 KB Output is correct
84 Correct 229 ms 135160 KB Output is correct
85 Correct 241 ms 135316 KB Output is correct
86 Correct 243 ms 135292 KB Output is correct
87 Correct 221 ms 135288 KB Output is correct
88 Correct 278 ms 135288 KB Output is correct
89 Correct 266 ms 135336 KB Output is correct
90 Correct 201 ms 135160 KB Output is correct
91 Correct 282 ms 135256 KB Output is correct
92 Correct 280 ms 135288 KB Output is correct
93 Correct 240 ms 135252 KB Output is correct