답안 #968717

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968717 2024-04-23T23:14:09 Z raphaelp Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
497 ms 446960 KB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long N, L;
    cin >> N >> L;
    vector<pair<long long, long long>> Tab(N);
    for (long long i = 0; i < N; i++)
        cin >> Tab[i].first;
    for (long long i = 0; i < N; i++)
        cin >> Tab[i].second;
    sort(Tab.begin(), Tab.end());
    vector<vector<vector<vector<long long>>>> dp(N, vector<vector<vector<long long>>>(N, vector<vector<long long>>(N + 2, vector<long long>(2, 12345678900000000))));
    long long maxx = 0;
    dp[0][0][(Tab[0].first <= Tab[0].second) ? 1 : 0][0] = Tab[0].first;
    dp[N - 1][N - 1][(L - Tab[N - 1].first <= Tab[N - 1].second) ? 1 : 0][1] = L - Tab[N - 1].first;
    for (long long i = 0; i < N; i++)
    {
        for (long long left = 0; left < N; left++)
        {
            long long right = (left + N - i) % N;
            for (long long nb = 0; nb <= N; nb++)
            {
                if (nb > i + 1)
                    continue;
                if (min(dp[left][right][nb][0], dp[left][right][nb][1]) == 12345678900000000)
                    continue;
                maxx = max(maxx, nb);
                long long next = (left + 1) % N, dist = (Tab[left].first < Tab[next].first) ? Tab[next].first - Tab[left].first : Tab[next].first + L - Tab[left].first;
                dp[next][right][(dp[left][right][nb][0] + dist > Tab[next].second) ? nb : nb + 1][0] = min(dp[left][right][nb][0] + dist, dp[next][right][(dp[left][right][nb][0] + dist > Tab[next].second) ? nb : nb + 1][0]);
                next = (left + 1) % N, dist = (Tab[right].first < Tab[next].first) ? Tab[next].first - Tab[right].first : Tab[next].first + L - Tab[right].first;
                dp[next][right][(dp[left][right][nb][1] + dist > Tab[next].second) ? nb : nb + 1][0] = min(dp[left][right][nb][1] + dist, dp[next][right][(dp[left][right][nb][1] + dist > Tab[next].second) ? nb : nb + 1][0]);
                next = (right - 1 + N) % N, dist = (Tab[right].first > Tab[next].first) ? Tab[right].first - Tab[next].first : Tab[right].first + L - Tab[next].first;
                dp[left][next][(dp[left][right][nb][1] + dist > Tab[next].second) ? nb : nb + 1][1] = min(dp[left][right][nb][1] + dist, dp[left][next][(dp[left][right][nb][1] + dist > Tab[next].second) ? nb : nb + 1][1]);
                next = (right - 1 + N) % N, dist = (Tab[left].first > Tab[next].first) ? Tab[left].first - Tab[next].first : Tab[left].first + L - Tab[next].first;
                dp[left][next][(dp[left][right][nb][0] + dist > Tab[next].second) ? nb : nb + 1][1] = min(dp[left][right][nb][0] + dist, dp[left][next][(dp[left][right][nb][0] + dist > Tab[next].second) ? nb : nb + 1][1]);
            }
        }
    }
    cout << maxx;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 432 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 0 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 368 ms 320980 KB Output is correct
19 Correct 168 ms 151192 KB Output is correct
20 Correct 84 ms 58708 KB Output is correct
21 Correct 160 ms 138692 KB Output is correct
22 Correct 223 ms 205404 KB Output is correct
23 Correct 54 ms 46200 KB Output is correct
24 Correct 37 ms 31828 KB Output is correct
25 Correct 53 ms 44636 KB Output is correct
26 Correct 11 ms 10584 KB Output is correct
27 Correct 56 ms 47640 KB Output is correct
28 Correct 34 ms 28508 KB Output is correct
29 Correct 60 ms 49184 KB Output is correct
30 Correct 41 ms 34256 KB Output is correct
31 Correct 52 ms 44792 KB Output is correct
32 Correct 19 ms 16992 KB Output is correct
33 Correct 52 ms 44620 KB Output is correct
34 Correct 10 ms 9816 KB Output is correct
35 Correct 53 ms 43356 KB Output is correct
36 Correct 15 ms 14168 KB Output is correct
37 Correct 55 ms 47708 KB Output is correct
38 Correct 24 ms 19384 KB Output is correct
39 Correct 58 ms 50780 KB Output is correct
40 Correct 29 ms 22752 KB Output is correct
41 Correct 491 ms 439852 KB Output is correct
42 Correct 264 ms 243144 KB Output is correct
43 Correct 458 ms 439888 KB Output is correct
44 Correct 254 ms 238556 KB Output is correct
45 Correct 466 ms 439928 KB Output is correct
46 Correct 256 ms 242780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 432 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 0 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 368 ms 320980 KB Output is correct
37 Correct 168 ms 151192 KB Output is correct
38 Correct 84 ms 58708 KB Output is correct
39 Correct 160 ms 138692 KB Output is correct
40 Correct 223 ms 205404 KB Output is correct
41 Correct 54 ms 46200 KB Output is correct
42 Correct 37 ms 31828 KB Output is correct
43 Correct 53 ms 44636 KB Output is correct
44 Correct 11 ms 10584 KB Output is correct
45 Correct 56 ms 47640 KB Output is correct
46 Correct 34 ms 28508 KB Output is correct
47 Correct 60 ms 49184 KB Output is correct
48 Correct 41 ms 34256 KB Output is correct
49 Correct 52 ms 44792 KB Output is correct
50 Correct 19 ms 16992 KB Output is correct
51 Correct 52 ms 44620 KB Output is correct
52 Correct 10 ms 9816 KB Output is correct
53 Correct 53 ms 43356 KB Output is correct
54 Correct 15 ms 14168 KB Output is correct
55 Correct 55 ms 47708 KB Output is correct
56 Correct 24 ms 19384 KB Output is correct
57 Correct 58 ms 50780 KB Output is correct
58 Correct 29 ms 22752 KB Output is correct
59 Correct 491 ms 439852 KB Output is correct
60 Correct 264 ms 243144 KB Output is correct
61 Correct 458 ms 439888 KB Output is correct
62 Correct 254 ms 238556 KB Output is correct
63 Correct 466 ms 439928 KB Output is correct
64 Correct 256 ms 242780 KB Output is correct
65 Correct 408 ms 377172 KB Output is correct
66 Correct 371 ms 331748 KB Output is correct
67 Correct 337 ms 310356 KB Output is correct
68 Correct 302 ms 275532 KB Output is correct
69 Correct 430 ms 371744 KB Output is correct
70 Correct 381 ms 348796 KB Output is correct
71 Correct 368 ms 353956 KB Output is correct
72 Correct 390 ms 360092 KB Output is correct
73 Correct 329 ms 320848 KB Output is correct
74 Correct 319 ms 290012 KB Output is correct
75 Correct 353 ms 337508 KB Output is correct
76 Correct 448 ms 414280 KB Output is correct
77 Correct 426 ms 414032 KB Output is correct
78 Correct 305 ms 280044 KB Output is correct
79 Correct 323 ms 295452 KB Output is correct
80 Correct 448 ms 401556 KB Output is correct
81 Correct 318 ms 300068 KB Output is correct
82 Correct 448 ms 326432 KB Output is correct
83 Correct 453 ms 440144 KB Output is correct
84 Correct 366 ms 348688 KB Output is correct
85 Correct 406 ms 395600 KB Output is correct
86 Correct 406 ms 383572 KB Output is correct
87 Correct 393 ms 337960 KB Output is correct
88 Correct 482 ms 446908 KB Output is correct
89 Correct 479 ms 446928 KB Output is correct
90 Correct 346 ms 342868 KB Output is correct
91 Correct 472 ms 446960 KB Output is correct
92 Correct 497 ms 446956 KB Output is correct
93 Correct 451 ms 433776 KB Output is correct