Submission #361597

# Submission time Handle Problem Language Result Execution time Memory
361597 2021-01-30T18:56:22 Z saarang123 Collecting Stamps 3 (JOI20_ho_t3) C++14
15 / 100
506 ms 282484 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 207;
const int inf = 1e18;
int dp[N][N][2][N]; //no (l, r), side, stamps
int x[N], t[N];
int n, m;
signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    #ifdef saarang
    freopen("/home/saarang/Documents/cp/input.txt", "r", stdin);
    freopen("/home/saarang/Documents/cp/output.txt", "w", stdout);
    #endif
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    	cin >> x[i];
    x[n + 1] = m;
    for(int i = 1; i <= n; i++)
    	cin >> t[i];
    for(int i = 0; i <= n + 2; i++)
    	for(int j = 0; j <= n + 2; j++)
    		for(int k = 0; k < 2; k++)
    			for(int l = 0; l <= n + 2; l++)
    				dp[i][j][k][l] = inf;
    dp[0][n + 1][0][0] = dp[0][n + 1][1][0] = 0;
    for(int i = 0; i < n; i++) {
    	for(int j = n + 1; j > i + 1; j--) {
    		for(int k = 0; k <= m; k++) {
    			int time = min(dp[i][j][0][k] + (x[i + 1] - x[i]), dp[i][j][1][k] + (m - x[j] + x[i + 1]));  //include i
    			dp[i + 1][j][0][k + (time <= t[i + 1])] = min(dp[i + 1][j][0][k + (time <= t[i + 1])], time);
    			time = min(dp[i][j][0][k] + (m - x[j - 1] + x[i]), dp[i][j][1][k] + (x[j] - x[j - 1]));
    			dp[i][j - 1][1][k + (time <= t[j - 1])] = min(dp[i][j - 1][1][k + (time <= t[j - 1])], time); //include j
    		}
    	}
    }
    int ans = 0;
    for(int i = 0; i <= n + 1; i++)
    	for(int j = 0; j <= n + 1; j++)
    		for(int k = 0; k < 2; k++)
    			for(int l = 0; l <= n; l++)
    				if(dp[i][j][k][l] != inf)
    					ans = max(ans, l);
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 876 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 1 ms 1132 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 1132 KB Output is correct
17 Correct 1 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 876 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 1 ms 1132 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 1132 KB Output is correct
17 Correct 1 ms 1132 KB Output is correct
18 Runtime error 506 ms 282484 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 876 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 1 ms 1132 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 1132 KB Output is correct
17 Correct 1 ms 1132 KB Output is correct
18 Correct 122 ms 108396 KB Output is correct
19 Correct 72 ms 66284 KB Output is correct
20 Correct 41 ms 35820 KB Output is correct
21 Correct 72 ms 62572 KB Output is correct
22 Correct 90 ms 80880 KB Output is correct
23 Correct 35 ms 30572 KB Output is correct
24 Correct 27 ms 24044 KB Output is correct
25 Correct 34 ms 29932 KB Output is correct
26 Correct 12 ms 11884 KB Output is correct
27 Correct 36 ms 31212 KB Output is correct
28 Correct 25 ms 22380 KB Output is correct
29 Correct 37 ms 31852 KB Output is correct
30 Correct 28 ms 25280 KB Output is correct
31 Correct 34 ms 29932 KB Output is correct
32 Correct 17 ms 15980 KB Output is correct
33 Correct 34 ms 29932 KB Output is correct
34 Correct 12 ms 11116 KB Output is correct
35 Correct 33 ms 29292 KB Output is correct
36 Correct 16 ms 14316 KB Output is correct
37 Correct 35 ms 31212 KB Output is correct
38 Correct 19 ms 17388 KB Output is correct
39 Correct 37 ms 32492 KB Output is correct
40 Correct 24 ms 19308 KB Output is correct
41 Correct 156 ms 133376 KB Output is correct
42 Correct 101 ms 90292 KB Output is correct
43 Correct 157 ms 133484 KB Output is correct
44 Correct 100 ms 89324 KB Output is correct
45 Correct 155 ms 133356 KB Output is correct
46 Correct 98 ms 90348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 876 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 1 ms 1132 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 1132 KB Output is correct
17 Correct 1 ms 1132 KB Output is correct
18 Runtime error 506 ms 282484 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -