답안 #201475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201475 2020-02-10T16:51:47 Z Alexa2001 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
101 ms 66680 KB
#include <bits/stdc++.h>

using namespace std;

const int inf = 1e9 + 99;
const int Nmax = 205;

int dp[Nmax][Nmax][Nmax][2];
int n, L, d[Nmax], t[Nmax];
int ans = 0;

void min_to(int &x, int y)
{
    if(x > y) x = y;
}

int main()
{
 //   freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> n >> L;
    int i, j, k;
    for(i=1; i<=n; ++i) cin >> d[i];
    for(i=1; i<=n; ++i) cin >> t[i];

    d[0] = 0; d[n+1] = L;

    for(i=0; i<=n+1; ++i)
        for(j=0; j<=n+1;++j)
            for(k=0; k<=n+1; ++k)
                dp[i][j][k][0] = dp[i][j][k][1] = inf;

    dp[n+1][0][0][0] = dp[n+1][0][0][1] = 0;

    for(i=n+1; i; --i)
        for(j=0; j<i; ++j)
            for(k=0; k<=n; ++k)
            {
                int tmp;
           //     if(i == 4) exit(0);
                
                if(dp[i][j][k][0] < inf)
                {
                    /// 0, j -> j+1
                    if(j + 1 < i)
                    {
                        tmp = dp[i][j][k][0] + (d[j+1] - d[j]);
                        min_to(dp[i][j+1][k + (tmp <= t[j+1])][0], tmp);
                    }

                    /// 0, i->i-1
                    if(j < i-1)
                    {
                        tmp = dp[i][j][k][0] + d[j] + (L - d[i-1]);
                        min_to(dp[i-1][j][k + (tmp <= t[i-1])][1], tmp);
                    }

                    ans = max(ans, k);
            //        cerr << i << ' ' << j << ' ' << k << ' ' << 0 << ' ' << dp[i][j][k][0] << '\n';
                } 


                if(dp[i][j][k][1] < inf)
                {
                    /// 1, i->i-1
                    if(j < i-1)
                    {
                        tmp = dp[i][j][k][1] + (d[i] - d[i-1]);
                        min_to(dp[i-1][j][k + (tmp <= t[i-1])][1], tmp);
                    }

                    /// 1, j->j+1
                    if(j + 1 < i)
                    {
                        tmp = dp[i][j][k][1] + (L - d[i]) + d[j+1];
                        min_to(dp[i][j+1][k + (tmp <= t[j+1])][0], tmp);
                    }
                    
                    ans = max(ans, k);
              //      cerr << i << ' ' << j << ' ' << k << ' ' << 1 << ' ' << dp[i][j][k][1] << '\n';
                }
            }

    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 760 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 760 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 5 ms 760 KB Output is correct
19 Correct 5 ms 632 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 5 ms 760 KB Output is correct
22 Correct 5 ms 632 KB Output is correct
23 Correct 5 ms 888 KB Output is correct
24 Correct 5 ms 760 KB Output is correct
25 Correct 5 ms 760 KB Output is correct
26 Correct 5 ms 760 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 508 KB Output is correct
29 Correct 5 ms 888 KB Output is correct
30 Correct 5 ms 888 KB Output is correct
31 Correct 5 ms 760 KB Output is correct
32 Correct 5 ms 760 KB Output is correct
33 Correct 5 ms 888 KB Output is correct
34 Correct 5 ms 888 KB Output is correct
35 Correct 5 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 760 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 61 ms 53752 KB Output is correct
19 Correct 36 ms 32760 KB Output is correct
20 Correct 20 ms 17656 KB Output is correct
21 Correct 32 ms 30968 KB Output is correct
22 Correct 45 ms 39928 KB Output is correct
23 Correct 19 ms 15096 KB Output is correct
24 Correct 12 ms 11896 KB Output is correct
25 Correct 17 ms 14968 KB Output is correct
26 Correct 8 ms 6008 KB Output is correct
27 Correct 17 ms 15480 KB Output is correct
28 Correct 12 ms 11176 KB Output is correct
29 Correct 17 ms 15736 KB Output is correct
30 Correct 12 ms 12536 KB Output is correct
31 Correct 16 ms 14840 KB Output is correct
32 Correct 10 ms 7928 KB Output is correct
33 Correct 16 ms 14840 KB Output is correct
34 Correct 8 ms 5628 KB Output is correct
35 Correct 14 ms 14584 KB Output is correct
36 Correct 9 ms 7160 KB Output is correct
37 Correct 14 ms 15480 KB Output is correct
38 Correct 10 ms 8696 KB Output is correct
39 Correct 15 ms 16120 KB Output is correct
40 Correct 10 ms 9592 KB Output is correct
41 Correct 85 ms 66040 KB Output is correct
42 Correct 33 ms 44668 KB Output is correct
43 Correct 101 ms 65912 KB Output is correct
44 Correct 31 ms 44152 KB Output is correct
45 Correct 81 ms 65912 KB Output is correct
46 Correct 32 ms 44664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 760 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 5 ms 760 KB Output is correct
19 Correct 5 ms 632 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 5 ms 760 KB Output is correct
22 Correct 5 ms 632 KB Output is correct
23 Correct 5 ms 888 KB Output is correct
24 Correct 5 ms 760 KB Output is correct
25 Correct 5 ms 760 KB Output is correct
26 Correct 5 ms 760 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 508 KB Output is correct
29 Correct 5 ms 888 KB Output is correct
30 Correct 5 ms 888 KB Output is correct
31 Correct 5 ms 760 KB Output is correct
32 Correct 5 ms 760 KB Output is correct
33 Correct 5 ms 888 KB Output is correct
34 Correct 5 ms 888 KB Output is correct
35 Correct 5 ms 888 KB Output is correct
36 Correct 61 ms 53752 KB Output is correct
37 Correct 36 ms 32760 KB Output is correct
38 Correct 20 ms 17656 KB Output is correct
39 Correct 32 ms 30968 KB Output is correct
40 Correct 45 ms 39928 KB Output is correct
41 Correct 19 ms 15096 KB Output is correct
42 Correct 12 ms 11896 KB Output is correct
43 Correct 17 ms 14968 KB Output is correct
44 Correct 8 ms 6008 KB Output is correct
45 Correct 17 ms 15480 KB Output is correct
46 Correct 12 ms 11176 KB Output is correct
47 Correct 17 ms 15736 KB Output is correct
48 Correct 12 ms 12536 KB Output is correct
49 Correct 16 ms 14840 KB Output is correct
50 Correct 10 ms 7928 KB Output is correct
51 Correct 16 ms 14840 KB Output is correct
52 Correct 8 ms 5628 KB Output is correct
53 Correct 14 ms 14584 KB Output is correct
54 Correct 9 ms 7160 KB Output is correct
55 Correct 14 ms 15480 KB Output is correct
56 Correct 10 ms 8696 KB Output is correct
57 Correct 15 ms 16120 KB Output is correct
58 Correct 10 ms 9592 KB Output is correct
59 Correct 85 ms 66040 KB Output is correct
60 Correct 33 ms 44668 KB Output is correct
61 Correct 101 ms 65912 KB Output is correct
62 Correct 31 ms 44152 KB Output is correct
63 Correct 81 ms 65912 KB Output is correct
64 Correct 32 ms 44664 KB Output is correct
65 Correct 45 ms 59680 KB Output is correct
66 Correct 43 ms 54780 KB Output is correct
67 Correct 40 ms 52472 KB Output is correct
68 Correct 38 ms 48504 KB Output is correct
69 Correct 47 ms 59004 KB Output is correct
70 Correct 45 ms 56568 KB Output is correct
71 Correct 40 ms 57212 KB Output is correct
72 Correct 44 ms 57720 KB Output is correct
73 Correct 39 ms 53752 KB Output is correct
74 Correct 40 ms 50168 KB Output is correct
75 Correct 38 ms 55416 KB Output is correct
76 Correct 60 ms 63352 KB Output is correct
77 Correct 46 ms 63352 KB Output is correct
78 Correct 43 ms 49016 KB Output is correct
79 Correct 39 ms 50680 KB Output is correct
80 Correct 59 ms 62072 KB Output is correct
81 Correct 36 ms 51320 KB Output is correct
82 Correct 47 ms 54136 KB Output is correct
83 Correct 47 ms 65888 KB Output is correct
84 Correct 48 ms 56568 KB Output is correct
85 Correct 43 ms 61432 KB Output is correct
86 Correct 51 ms 60280 KB Output is correct
87 Correct 40 ms 55416 KB Output is correct
88 Correct 53 ms 66680 KB Output is correct
89 Correct 47 ms 66552 KB Output is correct
90 Correct 40 ms 56056 KB Output is correct
91 Correct 53 ms 66552 KB Output is correct
92 Correct 48 ms 66552 KB Output is correct
93 Correct 45 ms 65272 KB Output is correct