답안 #900164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900164 2024-01-07T19:31:27 Z andrei_iorgulescu Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
40 ms 134020 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int inf = 1e18;

int n,l,x[205],t[205];
int dp[205][205][205][2];
int sp[205];

int dist(int px,int py)
{
    return x[py] - x[px];
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> l;
    for (int i = 1; i <= n; i++)
        cin >> x[i];
    x[n + 1] = l;
    for (int i = 1; i <= n; i++)
        cin >> t[i];
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            for (int q = 0; q <= n; q++)
                for (int c = 0; c < 2; c++)
                    dp[i][j][q][c] = inf;
    dp[0][0][0][0] = dp[0][0][0][1] = 0;
    for (int i = 0; i <= n - 1; i++)
    {
        for (int j = 0; j <= n - 1 - i; j++)
        {
            for (int k = 0; k <= i + j; k++)
            {
                //cout << i << ' ' << j << ' ' << k << ' ' << dp[i][j][k][0] << ' ' << dp[i][j][k][1] << endl;
                //cout << i << ' ' << j << ' ' << k << ' ';
                int t0 = dp[i][j][k][0] + dist(n - i,n - i + 1);
                if (t0 <= t[n - i])
                    dp[i + 1][j][k + 1][0] = min(dp[i + 1][j][k + 1][0],t0);
                else
                    dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0],t0);
                int t1 = dp[i][j][k][0] + l - dist(j + 1,n - i + 1);
                if (t1 <= t[j + 1])
                    dp[i][j + 1][k + 1][1] = min(dp[i][j + 1][k + 1][1],t1);
                else
                    dp[i][j + 1][k][1] = min(dp[i][j + 1][k][1],t1);
                int t2 = dp[i][j][k][1] + l - dist(j,n - i);
                if (t2 <= t[n - i])
                    dp[i + 1][j][k + 1][0] = min(dp[i + 1][j][k + 1][0],t2);
                else
                    dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0],t2);
                int t3 = dp[i][j][k][1] + dist(j,j + 1);
                if (t3 <= t[j + 1])
                    dp[i][j + 1][k + 1][1] = min(dp[i][j + 1][k + 1][1],t3);
                else
                    dp[i][j + 1][k][1] = min(dp[i][j + 1][k][1],t3);
                //cout << t0 << ' ' << t1 << ' ' << t2 << ' ' << t3 << endl;
            }
        }
    }
    for (int i = n; i >= 1; i--)
    {
        bool pot = false;
        for (int j = 0; j <= n; j++)
        {
            int q = n - j;
            if (dp[j][q][i][0] < inf or dp[j][q][i][1] < inf)
                pot = true;
        }
        if (pot == true)
        {
            cout << i;
            return 0;
        }
    }
    cout << 0;
    return 0;
}

/**
presupun ca exista punctul 0, apoi in dreapta punctele sunt 1,2,...,n iar in stanga sunt n,n-1,...,1
**/

/**
dp[i][j][k][0/1] -> care este timpul minim la care sa fiu la i in stanga (0) sau j in dreapta (1) a.i am acoperit interv [i j] si am k stamp-uri
{i,j,k,0} -> {i + 1,j,k sau k + 1 in functie de timp,0} sau {i,j + 1,k sau k + 1 in functie de timp,1}
{i,j,k,1} -> {i + 1,j,k sau k + 1 in functie de timp,0} sau {i,j + 1,k sau k + 1 in functie de timp,1}
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 6608 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 6608 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8536 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 1 ms 6604 KB Output is correct
23 Correct 1 ms 10588 KB Output is correct
24 Correct 1 ms 10696 KB Output is correct
25 Correct 1 ms 10584 KB Output is correct
26 Correct 1 ms 10708 KB Output is correct
27 Correct 1 ms 6488 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 10700 KB Output is correct
30 Correct 1 ms 10584 KB Output is correct
31 Correct 1 ms 10588 KB Output is correct
32 Correct 1 ms 10588 KB Output is correct
33 Correct 1 ms 10588 KB Output is correct
34 Correct 2 ms 10704 KB Output is correct
35 Correct 1 ms 10704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 6608 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8536 KB Output is correct
18 Correct 40 ms 119612 KB Output is correct
19 Correct 17 ms 92764 KB Output is correct
20 Correct 10 ms 68188 KB Output is correct
21 Correct 16 ms 90716 KB Output is correct
22 Correct 20 ms 103248 KB Output is correct
23 Correct 9 ms 62044 KB Output is correct
24 Correct 7 ms 55900 KB Output is correct
25 Correct 9 ms 62044 KB Output is correct
26 Correct 5 ms 37876 KB Output is correct
27 Correct 10 ms 64092 KB Output is correct
28 Correct 8 ms 53852 KB Output is correct
29 Correct 10 ms 64172 KB Output is correct
30 Correct 8 ms 55900 KB Output is correct
31 Correct 9 ms 62044 KB Output is correct
32 Correct 6 ms 45792 KB Output is correct
33 Correct 9 ms 62044 KB Output is correct
34 Correct 5 ms 37464 KB Output is correct
35 Correct 9 ms 62296 KB Output is correct
36 Correct 6 ms 41564 KB Output is correct
37 Correct 10 ms 64092 KB Output is correct
38 Correct 6 ms 47824 KB Output is correct
39 Correct 9 ms 64092 KB Output is correct
40 Correct 7 ms 49848 KB Output is correct
41 Correct 33 ms 133980 KB Output is correct
42 Correct 22 ms 109148 KB Output is correct
43 Correct 30 ms 134020 KB Output is correct
44 Correct 23 ms 109140 KB Output is correct
45 Correct 30 ms 134004 KB Output is correct
46 Correct 24 ms 109404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 6608 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8536 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 1 ms 8536 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 1 ms 6604 KB Output is correct
23 Correct 1 ms 10588 KB Output is correct
24 Correct 1 ms 10696 KB Output is correct
25 Correct 1 ms 10584 KB Output is correct
26 Correct 1 ms 10708 KB Output is correct
27 Correct 1 ms 6488 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 10700 KB Output is correct
30 Correct 1 ms 10584 KB Output is correct
31 Correct 1 ms 10588 KB Output is correct
32 Correct 1 ms 10588 KB Output is correct
33 Correct 1 ms 10588 KB Output is correct
34 Correct 2 ms 10704 KB Output is correct
35 Correct 1 ms 10704 KB Output is correct
36 Correct 40 ms 119612 KB Output is correct
37 Correct 17 ms 92764 KB Output is correct
38 Correct 10 ms 68188 KB Output is correct
39 Correct 16 ms 90716 KB Output is correct
40 Correct 20 ms 103248 KB Output is correct
41 Correct 9 ms 62044 KB Output is correct
42 Correct 7 ms 55900 KB Output is correct
43 Correct 9 ms 62044 KB Output is correct
44 Correct 5 ms 37876 KB Output is correct
45 Correct 10 ms 64092 KB Output is correct
46 Correct 8 ms 53852 KB Output is correct
47 Correct 10 ms 64172 KB Output is correct
48 Correct 8 ms 55900 KB Output is correct
49 Correct 9 ms 62044 KB Output is correct
50 Correct 6 ms 45792 KB Output is correct
51 Correct 9 ms 62044 KB Output is correct
52 Correct 5 ms 37464 KB Output is correct
53 Correct 9 ms 62296 KB Output is correct
54 Correct 6 ms 41564 KB Output is correct
55 Correct 10 ms 64092 KB Output is correct
56 Correct 6 ms 47824 KB Output is correct
57 Correct 9 ms 64092 KB Output is correct
58 Correct 7 ms 49848 KB Output is correct
59 Correct 33 ms 133980 KB Output is correct
60 Correct 22 ms 109148 KB Output is correct
61 Correct 30 ms 134020 KB Output is correct
62 Correct 23 ms 109140 KB Output is correct
63 Correct 30 ms 134004 KB Output is correct
64 Correct 24 ms 109404 KB Output is correct
65 Correct 29 ms 125784 KB Output is correct
66 Correct 26 ms 121680 KB Output is correct
67 Correct 27 ms 117592 KB Output is correct
68 Correct 26 ms 113748 KB Output is correct
69 Correct 27 ms 125788 KB Output is correct
70 Correct 26 ms 123736 KB Output is correct
71 Correct 26 ms 123740 KB Output is correct
72 Correct 26 ms 123548 KB Output is correct
73 Correct 25 ms 119644 KB Output is correct
74 Correct 23 ms 115456 KB Output is correct
75 Correct 26 ms 121684 KB Output is correct
76 Correct 33 ms 129992 KB Output is correct
77 Correct 28 ms 129884 KB Output is correct
78 Correct 26 ms 115544 KB Output is correct
79 Correct 24 ms 115564 KB Output is correct
80 Correct 29 ms 129880 KB Output is correct
81 Correct 24 ms 117596 KB Output is correct
82 Correct 25 ms 119448 KB Output is correct
83 Correct 30 ms 133980 KB Output is correct
84 Correct 26 ms 123740 KB Output is correct
85 Correct 32 ms 128088 KB Output is correct
86 Correct 28 ms 127720 KB Output is correct
87 Correct 26 ms 121692 KB Output is correct
88 Correct 31 ms 133980 KB Output is correct
89 Correct 32 ms 133968 KB Output is correct
90 Correct 26 ms 121688 KB Output is correct
91 Correct 31 ms 133980 KB Output is correct
92 Correct 31 ms 133976 KB Output is correct
93 Correct 31 ms 131932 KB Output is correct