답안 #906211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906211 2024-01-13T16:32:57 Z Marco_Escandon Collecting Stamps 3 (JOI20_ho_t3) C++11
100 / 100
448 ms 774424 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<ll,ll>> cad;
ll cost(ll a, ll b)
{
    return abs(cad[a].first-cad[b].first);
}
int main()
{
    ll n,l;
    cin>>n>>l;
    for(int i=0; i<n; i++)
    {
        ll temp;
        cin>>temp;
        cad.push_back({temp,0});
    }
    for(int i=0; i<n; i++)
    {
        ll temp;
        cin>>temp;
        cad[i].second=temp;
        cad.push_back({-(l-cad[i].first),cad[i].second});
    }
    cad.push_back({0,0});
    sort(cad.begin(),cad.end());
    ll p=0;
    for(int i=0; i<cad.size(); i++)
    {
        if(cad[i].first==0)
            p=i;
    }
    vector<vector<vector<vector<ll>>>> dp(2,vector<vector<vector<ll>>>(n+1,vector<vector<ll>>(cad.size()+1,vector<ll>(cad.size()+1,1e15))));
    dp[0][0][p][p]= 0;
    dp[1][0][p][p]= 0;
    ll bs=0;
    for(int k=0; k<=n; k++)
    {
        for(int i=p; i>-1; i--)
        {
            for(int j=p; j<cad.size()-(p-i); j++)
            {
                dp[0][k][i][j] = min(min(dp[1][k][i+1][j] + cost(i,j),dp[0][k][i+1][j] + cost(i,i+1)),dp[0][k][i][j]);
                dp[1][k][i][j] = min(min(dp[1][k][i][j-1] + cost(j,j-1),dp[0][k][i][j-1] + cost(i,j)),dp[1][k][i][j]);
                if(k>0)
                {
                    if(min(dp[1][k-1][i+1][j] + cost(i,j),dp[0][k-1][i+1][j] + cost(i,i+1))<=cad[i].second)
                    {
                        dp[0][k][i][j] = min(min(dp[1][k-1][i+1][j] + cost(i,j),dp[0][k-1][i+1][j] + cost(i,i+1)),dp[0][k][i][j]);
                    }
                    if(min(dp[1][k-1][i][j-1] + cost(j,j-1),dp[0][k-1][i][j-1] + cost(i,j))<=cad[j].second)
                    {
                        dp[1][k][i][j] = min(min(dp[1][k-1][i][j-1] + cost(j,j-1),dp[0][k-1][i][j-1] + cost(i,j)),dp[1][k][i][j]);
                    }
                }
                if(dp[0][k][i][j]!=1e15||dp[1][k][i][j]!=1e15) bs=k;
            }
        }
    }
    cout<<bs;
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i=0; i<cad.size(); i++)
      |                  ~^~~~~~~~~~~
ho_t3.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   42 |             for(int j=p; j<cad.size()-(p-i); j++)
      |                          ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 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 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 600 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 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 860 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 860 KB Output is correct
34 Correct 1 ms 860 KB Output is correct
35 Correct 1 ms 860 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 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 321 ms 556892 KB Output is correct
19 Correct 166 ms 263268 KB Output is correct
20 Correct 68 ms 102772 KB Output is correct
21 Correct 148 ms 241536 KB Output is correct
22 Correct 215 ms 356648 KB Output is correct
23 Correct 55 ms 80724 KB Output is correct
24 Correct 38 ms 55896 KB Output is correct
25 Correct 55 ms 78160 KB Output is correct
26 Correct 14 ms 18524 KB Output is correct
27 Correct 53 ms 83124 KB Output is correct
28 Correct 34 ms 50228 KB Output is correct
29 Correct 59 ms 85840 KB Output is correct
30 Correct 39 ms 59832 KB Output is correct
31 Correct 54 ms 78296 KB Output is correct
32 Correct 25 ms 29788 KB Output is correct
33 Correct 54 ms 78072 KB Output is correct
34 Correct 12 ms 16728 KB Output is correct
35 Correct 52 ms 75600 KB Output is correct
36 Correct 18 ms 24992 KB Output is correct
37 Correct 54 ms 83228 KB Output is correct
38 Correct 26 ms 34136 KB Output is correct
39 Correct 67 ms 88660 KB Output is correct
40 Correct 31 ms 39740 KB Output is correct
41 Correct 448 ms 762568 KB Output is correct
42 Correct 256 ms 421944 KB Output is correct
43 Correct 424 ms 762572 KB Output is correct
44 Correct 242 ms 414208 KB Output is correct
45 Correct 442 ms 762704 KB Output is correct
46 Correct 256 ms 421784 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 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 600 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 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 860 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 860 KB Output is correct
34 Correct 1 ms 860 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
36 Correct 321 ms 556892 KB Output is correct
37 Correct 166 ms 263268 KB Output is correct
38 Correct 68 ms 102772 KB Output is correct
39 Correct 148 ms 241536 KB Output is correct
40 Correct 215 ms 356648 KB Output is correct
41 Correct 55 ms 80724 KB Output is correct
42 Correct 38 ms 55896 KB Output is correct
43 Correct 55 ms 78160 KB Output is correct
44 Correct 14 ms 18524 KB Output is correct
45 Correct 53 ms 83124 KB Output is correct
46 Correct 34 ms 50228 KB Output is correct
47 Correct 59 ms 85840 KB Output is correct
48 Correct 39 ms 59832 KB Output is correct
49 Correct 54 ms 78296 KB Output is correct
50 Correct 25 ms 29788 KB Output is correct
51 Correct 54 ms 78072 KB Output is correct
52 Correct 12 ms 16728 KB Output is correct
53 Correct 52 ms 75600 KB Output is correct
54 Correct 18 ms 24992 KB Output is correct
55 Correct 54 ms 83228 KB Output is correct
56 Correct 26 ms 34136 KB Output is correct
57 Correct 67 ms 88660 KB Output is correct
58 Correct 31 ms 39740 KB Output is correct
59 Correct 448 ms 762568 KB Output is correct
60 Correct 256 ms 421944 KB Output is correct
61 Correct 424 ms 762572 KB Output is correct
62 Correct 242 ms 414208 KB Output is correct
63 Correct 442 ms 762704 KB Output is correct
64 Correct 256 ms 421784 KB Output is correct
65 Correct 369 ms 654172 KB Output is correct
66 Correct 331 ms 575512 KB Output is correct
67 Correct 320 ms 538448 KB Output is correct
68 Correct 280 ms 477800 KB Output is correct
69 Correct 367 ms 643920 KB Output is correct
70 Correct 353 ms 604128 KB Output is correct
71 Correct 347 ms 614112 KB Output is correct
72 Correct 358 ms 624012 KB Output is correct
73 Correct 329 ms 556880 KB Output is correct
74 Correct 297 ms 503512 KB Output is correct
75 Correct 332 ms 585220 KB Output is correct
76 Correct 405 ms 717984 KB Output is correct
77 Correct 407 ms 717960 KB Output is correct
78 Correct 284 ms 486480 KB Output is correct
79 Correct 297 ms 511976 KB Output is correct
80 Correct 393 ms 696376 KB Output is correct
81 Correct 303 ms 520756 KB Output is correct
82 Correct 323 ms 566016 KB Output is correct
83 Correct 422 ms 762452 KB Output is correct
84 Correct 347 ms 604496 KB Output is correct
85 Correct 383 ms 685648 KB Output is correct
86 Correct 376 ms 664524 KB Output is correct
87 Correct 333 ms 585040 KB Output is correct
88 Correct 428 ms 774004 KB Output is correct
89 Correct 438 ms 774424 KB Output is correct
90 Correct 339 ms 594516 KB Output is correct
91 Correct 437 ms 774172 KB Output is correct
92 Correct 436 ms 773852 KB Output is correct
93 Correct 425 ms 751204 KB Output is correct