Submission #364787

# Submission time Handle Problem Language Result Execution time Memory
364787 2021-02-10T03:30:20 Z cpp219 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
1877 ms 85404 KB
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 200 + 3;
const ll inf = 1e9 + 7;
typedef pair<int,int> LL;

ll n,lens,a[N],dp[N][N][N][2],lim[N];
ll ans;
struct Node{
    ll val,L,R,p,lr;
};
bool operator < (Node a,Node b){
    return a.val > b.val;
}
priority_queue<Node> pq;

ll Ask(ll L,ll R){
    return lens - a[L] + a[R];
}

void Minimize(ll L,ll R,ll p,ll lr,ll val){
    if (dp[L][R][p][lr] <= val) return; ans = max(ans,p);
    //cout<<L<<" "<<R<<" "<<p<<" "<<lr<<"x\n";
    dp[L][R][p][lr] = val; pq.push({val,L,R,p,lr});
}

void process(ll L,ll R,ll p,ll lr){}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        freopen(task".OUT","w",stdout);
    }
    cin>>n>>lens;
    for (ll i = 1;i <= n;i++) cin>>a[i];
    for (ll i = 1;i <= n;i++) cin>>lim[i];
    for (ll i = 0;i <= n;i++)
        for (ll j = 0;j <= n;j++)
            for (ll l = 0;l <= n;l++) dp[i][j][l][0] = dp[i][j][l][1] = inf;
    dp[0][0][0][0] = dp[0][0][0][1] = 0;
    pq.push({0,0,0,0,0}); pq.push({0,0,0,0,1});
    while(!pq.empty()){
        Node t = pq.top(); pq.pop();
        ll L = t.L,R = t.R,p = t.p,lr = t.lr,A = t.val,now1,now2;
        //cout<<L<<" "<<R<<" "<<p<<" "<<lr<<" x "<<A<<":\n";
        if (L - R == 1) continue;
        if (L == 0&&R == n) continue;
        ll nxtL = L - 1,nxtR = R + 1;
        if (!L) nxtL = n;
        if (!lr){
            now1 = A + a[L] - a[nxtL],now2 = A + Ask(L,R + 1);
            if (L == 0) now1 = A + lens - a[nxtL];
            //cout<<now1; return 0;
        }
        else{
            now1 = A + Ask(nxtL,R),now2 = A + a[R + 1] - a[R];
        }
        //cout<<now1<<" "<<lim[nxtL]; return 0;
        if (now1 <= lim[nxtL]) Minimize(nxtL,R,p + 1,0,now1);
        else Minimize(nxtL,R,p,0,now1);
        if (now2 <= lim[R + 1]) Minimize(L,R + 1,p + 1,1,now2);
        else Minimize(L,R + 1,p,1,now2); //cout<<"\n";
    }
    cout<<ans;
}

Compilation message

ho_t3.cpp: In function 'void Minimize(int, int, int, int, int)':
ho_t3.cpp:26:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   26 |     if (dp[L][R][p][lr] <= val) return; ans = max(ans,p);
      |     ^~
ho_t3.cpp:26:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   26 |     if (dp[L][R][p][lr] <= val) return; ans = max(ans,p);
      |                                         ^~~
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:55:25: warning: unused variable 'nxtR' [-Wunused-variable]
   55 |         ll nxtL = L - 1,nxtR = R + 1;
      |                         ^~~~
ho_t3.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   38 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   39 |         freopen(task".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 748 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 620 KB Output is correct
21 Correct 1 ms 748 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 896 KB Output is correct
24 Correct 1 ms 748 KB Output is correct
25 Correct 1 ms 748 KB Output is correct
26 Correct 1 ms 748 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 640 KB Output is correct
29 Correct 1 ms 896 KB Output is correct
30 Correct 1 ms 888 KB Output is correct
31 Correct 1 ms 748 KB Output is correct
32 Correct 1 ms 748 KB Output is correct
33 Correct 1 ms 896 KB Output is correct
34 Correct 1 ms 748 KB Output is correct
35 Correct 1 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 973 ms 62932 KB Output is correct
19 Correct 424 ms 42452 KB Output is correct
20 Correct 112 ms 19936 KB Output is correct
21 Correct 358 ms 35548 KB Output is correct
22 Correct 630 ms 49524 KB Output is correct
23 Correct 112 ms 17376 KB Output is correct
24 Correct 32 ms 13028 KB Output is correct
25 Correct 105 ms 17120 KB Output is correct
26 Correct 16 ms 6092 KB Output is correct
27 Correct 123 ms 17760 KB Output is correct
28 Correct 30 ms 12132 KB Output is correct
29 Correct 102 ms 18016 KB Output is correct
30 Correct 39 ms 13540 KB Output is correct
31 Correct 92 ms 17120 KB Output is correct
32 Correct 29 ms 8616 KB Output is correct
33 Correct 83 ms 15884 KB Output is correct
34 Correct 13 ms 6204 KB Output is correct
35 Correct 26 ms 14540 KB Output is correct
36 Correct 14 ms 7592 KB Output is correct
37 Correct 38 ms 15784 KB Output is correct
38 Correct 27 ms 9128 KB Output is correct
39 Correct 34 ms 16424 KB Output is correct
40 Correct 22 ms 10024 KB Output is correct
41 Correct 1817 ms 85316 KB Output is correct
42 Correct 37 ms 44108 KB Output is correct
43 Correct 1861 ms 85316 KB Output is correct
44 Correct 40 ms 43616 KB Output is correct
45 Correct 1877 ms 85404 KB Output is correct
46 Correct 35 ms 44108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 748 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 620 KB Output is correct
21 Correct 1 ms 748 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 896 KB Output is correct
24 Correct 1 ms 748 KB Output is correct
25 Correct 1 ms 748 KB Output is correct
26 Correct 1 ms 748 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 640 KB Output is correct
29 Correct 1 ms 896 KB Output is correct
30 Correct 1 ms 888 KB Output is correct
31 Correct 1 ms 748 KB Output is correct
32 Correct 1 ms 748 KB Output is correct
33 Correct 1 ms 896 KB Output is correct
34 Correct 1 ms 748 KB Output is correct
35 Correct 1 ms 748 KB Output is correct
36 Correct 973 ms 62932 KB Output is correct
37 Correct 424 ms 42452 KB Output is correct
38 Correct 112 ms 19936 KB Output is correct
39 Correct 358 ms 35548 KB Output is correct
40 Correct 630 ms 49524 KB Output is correct
41 Correct 112 ms 17376 KB Output is correct
42 Correct 32 ms 13028 KB Output is correct
43 Correct 105 ms 17120 KB Output is correct
44 Correct 16 ms 6092 KB Output is correct
45 Correct 123 ms 17760 KB Output is correct
46 Correct 30 ms 12132 KB Output is correct
47 Correct 102 ms 18016 KB Output is correct
48 Correct 39 ms 13540 KB Output is correct
49 Correct 92 ms 17120 KB Output is correct
50 Correct 29 ms 8616 KB Output is correct
51 Correct 83 ms 15884 KB Output is correct
52 Correct 13 ms 6204 KB Output is correct
53 Correct 26 ms 14540 KB Output is correct
54 Correct 14 ms 7592 KB Output is correct
55 Correct 38 ms 15784 KB Output is correct
56 Correct 27 ms 9128 KB Output is correct
57 Correct 34 ms 16424 KB Output is correct
58 Correct 22 ms 10024 KB Output is correct
59 Correct 1817 ms 85316 KB Output is correct
60 Correct 37 ms 44108 KB Output is correct
61 Correct 1861 ms 85316 KB Output is correct
62 Correct 40 ms 43616 KB Output is correct
63 Correct 1877 ms 85404 KB Output is correct
64 Correct 35 ms 44108 KB Output is correct
65 Correct 81 ms 59176 KB Output is correct
66 Correct 78 ms 54440 KB Output is correct
67 Correct 63 ms 51788 KB Output is correct
68 Correct 59 ms 47948 KB Output is correct
69 Correct 82 ms 58664 KB Output is correct
70 Correct 139 ms 56924 KB Output is correct
71 Correct 41 ms 56044 KB Output is correct
72 Correct 129 ms 57384 KB Output is correct
73 Correct 40 ms 52588 KB Output is correct
74 Correct 121 ms 50636 KB Output is correct
75 Correct 39 ms 54380 KB Output is correct
76 Correct 478 ms 64864 KB Output is correct
77 Correct 48 ms 62448 KB Output is correct
78 Correct 321 ms 49500 KB Output is correct
79 Correct 50 ms 50124 KB Output is correct
80 Correct 472 ms 63712 KB Output is correct
81 Correct 36 ms 50284 KB Output is correct
82 Correct 248 ms 55776 KB Output is correct
83 Correct 57 ms 64972 KB Output is correct
84 Correct 282 ms 58080 KB Output is correct
85 Correct 41 ms 60300 KB Output is correct
86 Correct 319 ms 61792 KB Output is correct
87 Correct 59 ms 54676 KB Output is correct
88 Correct 129 ms 65960 KB Output is correct
89 Correct 56 ms 65388 KB Output is correct
90 Correct 44 ms 55020 KB Output is correct
91 Correct 151 ms 65960 KB Output is correct
92 Correct 63 ms 65612 KB Output is correct
93 Correct 47 ms 64236 KB Output is correct