답안 #219599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
219599 2020-04-05T16:48:40 Z MKopchev Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
1634 ms 41560 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=2e2+5;
int n,circle;
int where[nmax],t_max[nmax];

int dp[nmax][nmax][nmax][2];//min time to get to state left position, right position, satisfied stamps, on left/right

priority_queue< pair< pair< pair< pair<int/*time*/,int/*left position*/>,int/*right position*/>,int/*satisfied*/>,int/*on left/right*/> > pq;

int calc_dist(int a,int b)
{
    int ret=abs(a-b);
    return min(ret,circle-ret);
}

void make_state(int t,int l_now,int r_now,int ok,bool side)
{
    //cout<<"making "<<t<<" "<<l_now<<" "<<r_now<<" "<<ok<<" "<<side<<endl;

    pq.push({{{{-t,l_now},r_now},ok},side});
}
int main()
{
    scanf("%i%i",&n,&circle);
    for(int i=1;i<=n;i++)scanf("%i",&where[i]);
    for(int i=1;i<=n;i++)scanf("%i",&t_max[i]);

    int MX_valid=0;
    for(int i=1;i<=n;i++)MX_valid=max(MX_valid,t_max[i]);

    //go to 1
    make_state(calc_dist(0,where[1]),1,n+1,calc_dist(0,where[1])<=t_max[1],0);

    //go to n
    make_state(calc_dist(0,where[n]),0,n,calc_dist(0,where[n])<=t_max[n],1);

    int output=0;
    while(pq.size())
    {
        pair< pair< pair< pair<int/*time*/,int/*left position*/>,int/*right position*/>,int/*satisfied*/>,int/*on left/right*/> use=pq.top();
        pq.pop();

        int t_now=-use.first.first.first.first;
        int l_now=use.first.first.first.second;
        int r_now=use.first.first.second;
        int satisfied=use.first.second;
        bool side=use.second;
        int location=(side==0?l_now:r_now);

        //cout<<t_now<<" "<<l_now<<" "<<r_now<<" "<<satisfied<<" "<<side<<" "<<location<<endl;

        output=max(output,satisfied);

        if(dp[l_now][r_now][satisfied][side])continue;
        dp[l_now][r_now][satisfied][side]=t_now;

        //[l_now+1...r_now-1] are remaining
        if(l_now+1>r_now-1)continue;

        if(t_now>MX_valid)continue;
        //go to l_now
        make_state(t_now+calc_dist(where[location],where[l_now+1]),l_now+1,r_now,satisfied+(t_now+calc_dist(where[location],where[l_now+1])<=t_max[l_now+1]),0);
        //go to r_now
        make_state(t_now+calc_dist(where[location],where[r_now-1]),l_now,r_now-1,satisfied+(t_now+calc_dist(where[location],where[r_now-1])<=t_max[r_now-1]),1);

        //cout<<"---"<<endl;
    }
    printf("%i\n",output);
    return 0;
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i",&n,&circle);
     ~~~~~^~~~~~~~~~~~~~~~~~~
ho_t3.cpp:26:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++)scanf("%i",&where[i]);
                          ~~~~~^~~~~~~~~~~~~~~~
ho_t3.cpp:27:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++)scanf("%i",&t_max[i]);
                          ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 640 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 640 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 640 KB Output is correct
34 Correct 5 ms 640 KB Output is correct
35 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 123 ms 24280 KB Output is correct
19 Correct 92 ms 16868 KB Output is correct
20 Correct 27 ms 8312 KB Output is correct
21 Correct 61 ms 14828 KB Output is correct
22 Correct 69 ms 17644 KB Output is correct
23 Correct 38 ms 8184 KB Output is correct
24 Correct 5 ms 1408 KB Output is correct
25 Correct 41 ms 8048 KB Output is correct
26 Correct 5 ms 1280 KB Output is correct
27 Correct 42 ms 8432 KB Output is correct
28 Correct 5 ms 1536 KB Output is correct
29 Correct 67 ms 9192 KB Output is correct
30 Correct 6 ms 2048 KB Output is correct
31 Correct 76 ms 8680 KB Output is correct
32 Correct 7 ms 2432 KB Output is correct
33 Correct 62 ms 8816 KB Output is correct
34 Correct 5 ms 1280 KB Output is correct
35 Correct 33 ms 7920 KB Output is correct
36 Correct 5 ms 1152 KB Output is correct
37 Correct 42 ms 8552 KB Output is correct
38 Correct 11 ms 3808 KB Output is correct
39 Correct 45 ms 8816 KB Output is correct
40 Correct 7 ms 1664 KB Output is correct
41 Correct 53 ms 24296 KB Output is correct
42 Correct 8 ms 3712 KB Output is correct
43 Correct 50 ms 24044 KB Output is correct
44 Correct 8 ms 3968 KB Output is correct
45 Correct 50 ms 24172 KB Output is correct
46 Correct 8 ms 3968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 640 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 640 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 640 KB Output is correct
34 Correct 5 ms 640 KB Output is correct
35 Correct 5 ms 640 KB Output is correct
36 Correct 123 ms 24280 KB Output is correct
37 Correct 92 ms 16868 KB Output is correct
38 Correct 27 ms 8312 KB Output is correct
39 Correct 61 ms 14828 KB Output is correct
40 Correct 69 ms 17644 KB Output is correct
41 Correct 38 ms 8184 KB Output is correct
42 Correct 5 ms 1408 KB Output is correct
43 Correct 41 ms 8048 KB Output is correct
44 Correct 5 ms 1280 KB Output is correct
45 Correct 42 ms 8432 KB Output is correct
46 Correct 5 ms 1536 KB Output is correct
47 Correct 67 ms 9192 KB Output is correct
48 Correct 6 ms 2048 KB Output is correct
49 Correct 76 ms 8680 KB Output is correct
50 Correct 7 ms 2432 KB Output is correct
51 Correct 62 ms 8816 KB Output is correct
52 Correct 5 ms 1280 KB Output is correct
53 Correct 33 ms 7920 KB Output is correct
54 Correct 5 ms 1152 KB Output is correct
55 Correct 42 ms 8552 KB Output is correct
56 Correct 11 ms 3808 KB Output is correct
57 Correct 45 ms 8816 KB Output is correct
58 Correct 7 ms 1664 KB Output is correct
59 Correct 53 ms 24296 KB Output is correct
60 Correct 8 ms 3712 KB Output is correct
61 Correct 50 ms 24044 KB Output is correct
62 Correct 8 ms 3968 KB Output is correct
63 Correct 50 ms 24172 KB Output is correct
64 Correct 8 ms 3968 KB Output is correct
65 Correct 99 ms 24520 KB Output is correct
66 Correct 117 ms 26980 KB Output is correct
67 Correct 90 ms 21088 KB Output is correct
68 Correct 69 ms 20196 KB Output is correct
69 Correct 148 ms 29272 KB Output is correct
70 Correct 321 ms 30948 KB Output is correct
71 Correct 9 ms 5632 KB Output is correct
72 Correct 304 ms 30688 KB Output is correct
73 Correct 5 ms 1408 KB Output is correct
74 Correct 280 ms 27340 KB Output is correct
75 Correct 11 ms 8032 KB Output is correct
76 Correct 1634 ms 36968 KB Output is correct
77 Correct 13 ms 8160 KB Output is correct
78 Correct 971 ms 28512 KB Output is correct
79 Correct 31 ms 12276 KB Output is correct
80 Correct 1553 ms 36568 KB Output is correct
81 Correct 10 ms 5988 KB Output is correct
82 Correct 622 ms 32308 KB Output is correct
83 Correct 26 ms 12664 KB Output is correct
84 Correct 697 ms 33640 KB Output is correct
85 Correct 6 ms 1792 KB Output is correct
86 Correct 792 ms 36828 KB Output is correct
87 Correct 59 ms 17380 KB Output is correct
88 Correct 382 ms 41560 KB Output is correct
89 Correct 55 ms 24044 KB Output is correct
90 Correct 8 ms 4224 KB Output is correct
91 Correct 335 ms 40664 KB Output is correct
92 Correct 57 ms 25832 KB Output is correct
93 Correct 8 ms 4224 KB Output is correct