답안 #1023043

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023043 2024-07-14T08:56:37 Z vjudge1 송신탑 (IOI22_towers) C++17
41 / 100
4000 ms 24264 KB
#include "towers.h"
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>

const int MAX=2e5+10;
const int inf=1e9;

struct segtree{
    int mx[4*MAX],mn[4*MAX],pmx[4*MAX];

    void build(int v,int tl,int tr,vector<int> &H){
        if(tl==tr){
            mx[v]=mn[v]=H[tl];
            pmx[v]=tl;
            return;
        }
        int tm=(tl+tr)/2;
        build(2*v,tl,tm,H);
        build(2*v+1,tm+1,tr,H);
        mx[v]=max(mx[2*v],mx[2*v+1]);
        if(mx[2*v]>mx[2*v+1])pmx[v]=pmx[2*v];
        else pmx[v]=pmx[2*v+1];
        mn[v]=min(mn[2*v],mn[2*v+1]);
    }

    int getMn(int v,int tl,int tr,int l,int r){
        if(l>r||tl>r||l>tr)return inf;
        if(l<=tl&&tr<=r)return mn[v];
        int tm=(tl+tr)/2;
        return min(getMn(2*v,tl,tm,l,r),getMn(2*v+1,tm+1,tr,l,r));
    }

    pii getMx(int v,int tl,int tr,int l,int r){
        if(l>r||tl>r||l>tr)return {-inf,-inf};
        if(l<=tl&&tr<=r)return {mx[v],pmx[v]};
        int tm=(tl+tr)/2;
        return max(getMx(2*v,tl,tm,l,r),getMx(2*v+1,tm+1,tr,l,r));
    }
}T;

int n,root;
vector<int> g[MAX];
int p[MAX];
int posMx=0;
bool sub;
vector<int> h;

int make_tree(int l,int r){
    if(l>r)return -1;
    auto [mx,pos]=T.getMx(1,0,n-1,l,r);
    int pos1=make_tree(l,pos-1);
    int pos2=make_tree(pos+1,r);
    if(pos1!=-1){
        g[pos].pb(pos1);
    }
    if(pos2!=-1)g[pos].pb(pos2);
    return pos;
}

void init(int N, vector<int> H) {

    sub=1;
    int cnt=0;
    for(int i=1;i<N-1;i++){
        if(H[i]>H[i-1]&&H[i]>H[i+1]){
            cnt++;
            // cout<<H[i-1]<<" "<<H[i]<<" "<<H[i+1]<<"\n";
        }
    }
    if(N>1){
        cnt+=(H[1]<H[0]);
        // cout<<(H[1]<H[0])<<"\n";
        cnt+=(H[N-2]<H[N-1]);
        // cout<<(H[N-2]<H[N-1])<<"\n";
    }
    // cout<<cnt<<"\n";
    if(cnt!=1)sub=0;
    for(int i=0;i<N;i++){
        if(H[i]>H[posMx])posMx=i;
    }
    h=H;

    T.build(1,0,N-1,H);
    n=N;
    root=make_tree(0,n-1);
    p[0]=g[0].empty();
    for(int i=1;i<N;i++)p[i]=p[i-1]+(g[i].empty());
}

int get(int l,int r,int d,int g){
    if(l>r)return 0;
    int ans=0;
    if(T.getMn(1,0,n-1,l,r)<=g){
        ans=1;
    }
    auto [mx,pos]=T.getMx(1,0,n-1,l,r);
    ans=max(ans,get(l,pos-1,d,mx-d)+get(pos+1,r,d,mx-d));
    return ans;
}

int get1(int l,int r){
    if(l==r)return 1;
    int ans=p[r]-(l>0?p[l-1]:0);
    if(sz(g[l])==1&&g[l][0]<l)ans++;
    if(sz(g[r])==1&&g[r][0]>r)ans++;
    return ans;
}

int max_towers(int L, int R, int D) {
    if(sub){
        if(L<posMx&&posMx<R){
            if(h[posMx]-D>=max(h[L],h[R]))return 2;
            return 1;
        }
        else return 1;
    }
    if(D==1){
        return get1(L,R);
    }
    return get(L,R,D,inf);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 333 ms 14680 KB Output is correct
2 Correct 733 ms 23128 KB Output is correct
3 Correct 680 ms 23380 KB Output is correct
4 Correct 692 ms 23632 KB Output is correct
5 Correct 708 ms 23632 KB Output is correct
6 Correct 666 ms 23632 KB Output is correct
7 Correct 640 ms 23708 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 3 ms 5464 KB Output is correct
10 Correct 4 ms 5464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 4 ms 5208 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 5 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 4 ms 5208 KB Output is correct
8 Correct 3 ms 5464 KB Output is correct
9 Correct 2 ms 5464 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 5 ms 5404 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 4 ms 5464 KB Output is correct
14 Correct 3 ms 5464 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 3 ms 5464 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5464 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5268 KB Output is correct
29 Correct 4 ms 5208 KB Output is correct
30 Correct 3 ms 5208 KB Output is correct
31 Correct 4 ms 5204 KB Output is correct
32 Correct 2 ms 5464 KB Output is correct
33 Correct 3 ms 5464 KB Output is correct
34 Correct 4 ms 5464 KB Output is correct
35 Correct 3 ms 5464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 4 ms 5208 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 5 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 4 ms 5208 KB Output is correct
8 Correct 3 ms 5464 KB Output is correct
9 Correct 2 ms 5464 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 5 ms 5404 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 4 ms 5464 KB Output is correct
14 Correct 3 ms 5464 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 3 ms 5464 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5464 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5268 KB Output is correct
29 Correct 4 ms 5208 KB Output is correct
30 Correct 3 ms 5208 KB Output is correct
31 Correct 4 ms 5204 KB Output is correct
32 Correct 2 ms 5464 KB Output is correct
33 Correct 3 ms 5464 KB Output is correct
34 Correct 4 ms 5464 KB Output is correct
35 Correct 3 ms 5464 KB Output is correct
36 Correct 26 ms 9052 KB Output is correct
37 Correct 46 ms 11856 KB Output is correct
38 Correct 36 ms 11824 KB Output is correct
39 Correct 35 ms 11340 KB Output is correct
40 Correct 32 ms 11344 KB Output is correct
41 Correct 46 ms 11348 KB Output is correct
42 Correct 32 ms 11340 KB Output is correct
43 Correct 45 ms 23632 KB Output is correct
44 Correct 41 ms 23632 KB Output is correct
45 Correct 49 ms 20816 KB Output is correct
46 Correct 32 ms 19540 KB Output is correct
47 Correct 32 ms 11868 KB Output is correct
48 Correct 30 ms 11348 KB Output is correct
49 Correct 34 ms 11344 KB Output is correct
50 Correct 32 ms 23632 KB Output is correct
51 Correct 35 ms 23632 KB Output is correct
52 Correct 42 ms 11628 KB Output is correct
53 Correct 29 ms 11340 KB Output is correct
54 Correct 37 ms 11172 KB Output is correct
55 Correct 32 ms 23716 KB Output is correct
56 Correct 38 ms 22864 KB Output is correct
57 Correct 53 ms 11600 KB Output is correct
58 Correct 52 ms 11856 KB Output is correct
59 Correct 52 ms 11856 KB Output is correct
60 Correct 53 ms 11344 KB Output is correct
61 Correct 55 ms 11344 KB Output is correct
62 Correct 51 ms 11352 KB Output is correct
63 Correct 50 ms 11344 KB Output is correct
64 Correct 35 ms 23632 KB Output is correct
65 Correct 42 ms 23632 KB Output is correct
66 Correct 58 ms 19912 KB Output is correct
67 Correct 54 ms 24264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 558 ms 11600 KB Output is correct
2 Correct 649 ms 11864 KB Output is correct
3 Correct 676 ms 11804 KB Output is correct
4 Correct 651 ms 11344 KB Output is correct
5 Correct 660 ms 11344 KB Output is correct
6 Correct 643 ms 11344 KB Output is correct
7 Correct 652 ms 11216 KB Output is correct
8 Correct 681 ms 23896 KB Output is correct
9 Correct 639 ms 23696 KB Output is correct
10 Correct 553 ms 21008 KB Output is correct
11 Correct 600 ms 21096 KB Output is correct
12 Correct 589 ms 23644 KB Output is correct
13 Correct 567 ms 23624 KB Output is correct
14 Correct 2 ms 4952 KB Output is correct
15 Correct 4 ms 5464 KB Output is correct
16 Correct 3 ms 5288 KB Output is correct
17 Correct 34 ms 11860 KB Output is correct
18 Correct 28 ms 11168 KB Output is correct
19 Correct 28 ms 11352 KB Output is correct
20 Correct 39 ms 23632 KB Output is correct
21 Correct 46 ms 23588 KB Output is correct
22 Correct 29 ms 11864 KB Output is correct
23 Correct 47 ms 11168 KB Output is correct
24 Correct 31 ms 11300 KB Output is correct
25 Correct 51 ms 23708 KB Output is correct
26 Correct 42 ms 22864 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 4 ms 5068 KB Output is correct
29 Correct 3 ms 5208 KB Output is correct
30 Correct 3 ms 5464 KB Output is correct
31 Correct 2 ms 5324 KB Output is correct
32 Correct 2 ms 5208 KB Output is correct
33 Correct 3 ms 5208 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 4 ms 5464 KB Output is correct
36 Correct 2 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4030 ms 6792 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 4 ms 5208 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 5 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 4 ms 5208 KB Output is correct
8 Correct 3 ms 5464 KB Output is correct
9 Correct 2 ms 5464 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 5 ms 5404 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 4 ms 5464 KB Output is correct
14 Correct 3 ms 5464 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 3 ms 5464 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5464 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5268 KB Output is correct
29 Correct 4 ms 5208 KB Output is correct
30 Correct 3 ms 5208 KB Output is correct
31 Correct 4 ms 5204 KB Output is correct
32 Correct 2 ms 5464 KB Output is correct
33 Correct 3 ms 5464 KB Output is correct
34 Correct 4 ms 5464 KB Output is correct
35 Correct 3 ms 5464 KB Output is correct
36 Correct 26 ms 9052 KB Output is correct
37 Correct 46 ms 11856 KB Output is correct
38 Correct 36 ms 11824 KB Output is correct
39 Correct 35 ms 11340 KB Output is correct
40 Correct 32 ms 11344 KB Output is correct
41 Correct 46 ms 11348 KB Output is correct
42 Correct 32 ms 11340 KB Output is correct
43 Correct 45 ms 23632 KB Output is correct
44 Correct 41 ms 23632 KB Output is correct
45 Correct 49 ms 20816 KB Output is correct
46 Correct 32 ms 19540 KB Output is correct
47 Correct 32 ms 11868 KB Output is correct
48 Correct 30 ms 11348 KB Output is correct
49 Correct 34 ms 11344 KB Output is correct
50 Correct 32 ms 23632 KB Output is correct
51 Correct 35 ms 23632 KB Output is correct
52 Correct 42 ms 11628 KB Output is correct
53 Correct 29 ms 11340 KB Output is correct
54 Correct 37 ms 11172 KB Output is correct
55 Correct 32 ms 23716 KB Output is correct
56 Correct 38 ms 22864 KB Output is correct
57 Correct 53 ms 11600 KB Output is correct
58 Correct 52 ms 11856 KB Output is correct
59 Correct 52 ms 11856 KB Output is correct
60 Correct 53 ms 11344 KB Output is correct
61 Correct 55 ms 11344 KB Output is correct
62 Correct 51 ms 11352 KB Output is correct
63 Correct 50 ms 11344 KB Output is correct
64 Correct 35 ms 23632 KB Output is correct
65 Correct 42 ms 23632 KB Output is correct
66 Correct 58 ms 19912 KB Output is correct
67 Correct 54 ms 24264 KB Output is correct
68 Correct 558 ms 11600 KB Output is correct
69 Correct 649 ms 11864 KB Output is correct
70 Correct 676 ms 11804 KB Output is correct
71 Correct 651 ms 11344 KB Output is correct
72 Correct 660 ms 11344 KB Output is correct
73 Correct 643 ms 11344 KB Output is correct
74 Correct 652 ms 11216 KB Output is correct
75 Correct 681 ms 23896 KB Output is correct
76 Correct 639 ms 23696 KB Output is correct
77 Correct 553 ms 21008 KB Output is correct
78 Correct 600 ms 21096 KB Output is correct
79 Correct 589 ms 23644 KB Output is correct
80 Correct 567 ms 23624 KB Output is correct
81 Correct 2 ms 4952 KB Output is correct
82 Correct 4 ms 5464 KB Output is correct
83 Correct 3 ms 5288 KB Output is correct
84 Correct 34 ms 11860 KB Output is correct
85 Correct 28 ms 11168 KB Output is correct
86 Correct 28 ms 11352 KB Output is correct
87 Correct 39 ms 23632 KB Output is correct
88 Correct 46 ms 23588 KB Output is correct
89 Correct 29 ms 11864 KB Output is correct
90 Correct 47 ms 11168 KB Output is correct
91 Correct 31 ms 11300 KB Output is correct
92 Correct 51 ms 23708 KB Output is correct
93 Correct 42 ms 22864 KB Output is correct
94 Correct 3 ms 5208 KB Output is correct
95 Correct 4 ms 5068 KB Output is correct
96 Correct 3 ms 5208 KB Output is correct
97 Correct 3 ms 5464 KB Output is correct
98 Correct 2 ms 5324 KB Output is correct
99 Correct 2 ms 5208 KB Output is correct
100 Correct 3 ms 5208 KB Output is correct
101 Correct 3 ms 5208 KB Output is correct
102 Correct 4 ms 5464 KB Output is correct
103 Correct 2 ms 5208 KB Output is correct
104 Execution timed out 4049 ms 11344 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 333 ms 14680 KB Output is correct
2 Correct 733 ms 23128 KB Output is correct
3 Correct 680 ms 23380 KB Output is correct
4 Correct 692 ms 23632 KB Output is correct
5 Correct 708 ms 23632 KB Output is correct
6 Correct 666 ms 23632 KB Output is correct
7 Correct 640 ms 23708 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 3 ms 5464 KB Output is correct
10 Correct 4 ms 5464 KB Output is correct
11 Correct 3 ms 4952 KB Output is correct
12 Correct 4 ms 5208 KB Output is correct
13 Correct 3 ms 5208 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 5 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 3 ms 5464 KB Output is correct
19 Correct 2 ms 5464 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 5 ms 5404 KB Output is correct
22 Correct 3 ms 4952 KB Output is correct
23 Correct 4 ms 5464 KB Output is correct
24 Correct 3 ms 5464 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5464 KB Output is correct
29 Correct 3 ms 5208 KB Output is correct
30 Correct 3 ms 5208 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 3 ms 5464 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 3 ms 5208 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 3 ms 5208 KB Output is correct
38 Correct 3 ms 5268 KB Output is correct
39 Correct 4 ms 5208 KB Output is correct
40 Correct 3 ms 5208 KB Output is correct
41 Correct 4 ms 5204 KB Output is correct
42 Correct 2 ms 5464 KB Output is correct
43 Correct 3 ms 5464 KB Output is correct
44 Correct 4 ms 5464 KB Output is correct
45 Correct 3 ms 5464 KB Output is correct
46 Correct 26 ms 9052 KB Output is correct
47 Correct 46 ms 11856 KB Output is correct
48 Correct 36 ms 11824 KB Output is correct
49 Correct 35 ms 11340 KB Output is correct
50 Correct 32 ms 11344 KB Output is correct
51 Correct 46 ms 11348 KB Output is correct
52 Correct 32 ms 11340 KB Output is correct
53 Correct 45 ms 23632 KB Output is correct
54 Correct 41 ms 23632 KB Output is correct
55 Correct 49 ms 20816 KB Output is correct
56 Correct 32 ms 19540 KB Output is correct
57 Correct 32 ms 11868 KB Output is correct
58 Correct 30 ms 11348 KB Output is correct
59 Correct 34 ms 11344 KB Output is correct
60 Correct 32 ms 23632 KB Output is correct
61 Correct 35 ms 23632 KB Output is correct
62 Correct 42 ms 11628 KB Output is correct
63 Correct 29 ms 11340 KB Output is correct
64 Correct 37 ms 11172 KB Output is correct
65 Correct 32 ms 23716 KB Output is correct
66 Correct 38 ms 22864 KB Output is correct
67 Correct 53 ms 11600 KB Output is correct
68 Correct 52 ms 11856 KB Output is correct
69 Correct 52 ms 11856 KB Output is correct
70 Correct 53 ms 11344 KB Output is correct
71 Correct 55 ms 11344 KB Output is correct
72 Correct 51 ms 11352 KB Output is correct
73 Correct 50 ms 11344 KB Output is correct
74 Correct 35 ms 23632 KB Output is correct
75 Correct 42 ms 23632 KB Output is correct
76 Correct 58 ms 19912 KB Output is correct
77 Correct 54 ms 24264 KB Output is correct
78 Correct 558 ms 11600 KB Output is correct
79 Correct 649 ms 11864 KB Output is correct
80 Correct 676 ms 11804 KB Output is correct
81 Correct 651 ms 11344 KB Output is correct
82 Correct 660 ms 11344 KB Output is correct
83 Correct 643 ms 11344 KB Output is correct
84 Correct 652 ms 11216 KB Output is correct
85 Correct 681 ms 23896 KB Output is correct
86 Correct 639 ms 23696 KB Output is correct
87 Correct 553 ms 21008 KB Output is correct
88 Correct 600 ms 21096 KB Output is correct
89 Correct 589 ms 23644 KB Output is correct
90 Correct 567 ms 23624 KB Output is correct
91 Correct 2 ms 4952 KB Output is correct
92 Correct 4 ms 5464 KB Output is correct
93 Correct 3 ms 5288 KB Output is correct
94 Correct 34 ms 11860 KB Output is correct
95 Correct 28 ms 11168 KB Output is correct
96 Correct 28 ms 11352 KB Output is correct
97 Correct 39 ms 23632 KB Output is correct
98 Correct 46 ms 23588 KB Output is correct
99 Correct 29 ms 11864 KB Output is correct
100 Correct 47 ms 11168 KB Output is correct
101 Correct 31 ms 11300 KB Output is correct
102 Correct 51 ms 23708 KB Output is correct
103 Correct 42 ms 22864 KB Output is correct
104 Correct 3 ms 5208 KB Output is correct
105 Correct 4 ms 5068 KB Output is correct
106 Correct 3 ms 5208 KB Output is correct
107 Correct 3 ms 5464 KB Output is correct
108 Correct 2 ms 5324 KB Output is correct
109 Correct 2 ms 5208 KB Output is correct
110 Correct 3 ms 5208 KB Output is correct
111 Correct 3 ms 5208 KB Output is correct
112 Correct 4 ms 5464 KB Output is correct
113 Correct 2 ms 5208 KB Output is correct
114 Execution timed out 4030 ms 6792 KB Time limit exceeded
115 Halted 0 ms 0 KB -