답안 #1035594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035594 2024-07-26T12:15:11 Z aymanrs 송신탑 (IOI22_towers) C++17
41 / 100
4000 ms 22100 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> pr, h;
const int K = 17;
vector<pair<int, int>> sp[K];
vector<int> spm[K];
inline int msb(int x){
    return 31-__builtin_clz(x);
}
int que(int l, int r){
  int d = msb(r-l+1);
  return max(sp[d][l], sp[d][r-(1<<d)+1]).second;
}
int qum(int l, int r){
  int d = msb(r-l+1);
  return min(spm[d][l], spm[d][r-(1<<d)+1]);
}
bool sub1 = true;
int th;
void init(int N, std::vector<int> H) {
  h = H;
  pr.resize(N);
  pr[0]=0;
  auto mx = max_element(h.begin(), h.end());
  if(is_sorted(h.begin(), mx) && is_sorted(mx, h.end(), greater<int>())) {
    sub1=true;
    th = mx-h.begin();
  }
  else sub1=false;
  for(int i = 0;i < K;i++) {
    sp[i].resize(N);
    spm[i].resize(N);
  }
  for(int i = 0;i < N;i++){
    sp[0][i] = {H[i], i};spm[0][i]=H[i];
  }
  for(int k = 1;k < K;k++){
    for(int i = 0;i+(1<<k)<=N;i++){
      sp[k][i] = max(sp[k-1][i], sp[k-1][i+(1<<k-1)]);
      spm[k][i] = min(spm[k-1][i], spm[k-1][i+(1<<k-1)]);
    }
  }
  for(int i = 1;i < N-1;i++){
    pr[i]=pr[i-1];
    if(H[i] < H[i-1] && H[i] < H[i+1]) pr[i]++;
  }
}
int de;
int ans(int l, int r, int atm){
  if(l==r){
    if(h[l]<=atm) return 1;
    return 0;
  }
  int m = que(l, r);
  if(l==m) return ans(l+1, r, atm);
  if(m==r) return ans(l, r-1, atm);
  return max(ans(l, m-1, h[m]-de)+ans(m+1, r, h[m]-de), (qum(l,r) <= atm ? 1 : 0));
}
int max_towers(int L, int R, int D) {
  if(sub1){
    if(L>th || R < th) return 1;
    return (h[R] <= h[th]-D && h[L] <= h[th]-D ? 2 : 1);
  }
  de = D;
  if(L+1>=R) return 1;
  if(D==1) return pr[R-1]-pr[L]+(h[L] < h[L+1])+(h[R]<h[R-1]);
  return ans(L, R, INT_MAX);
}

Compilation message

towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:40:49: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   40 |       sp[k][i] = max(sp[k-1][i], sp[k-1][i+(1<<k-1)]);
      |                                                ~^~
towers.cpp:41:52: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   41 |       spm[k][i] = min(spm[k-1][i], spm[k-1][i+(1<<k-1)]);
      |                                                   ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 326 ms 13144 KB Output is correct
2 Correct 637 ms 21848 KB Output is correct
3 Correct 610 ms 21848 KB Output is correct
4 Correct 612 ms 21828 KB Output is correct
5 Correct 682 ms 21848 KB Output is correct
6 Correct 545 ms 21944 KB Output is correct
7 Correct 643 ms 21848 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 676 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 668 KB Output is correct
14 Correct 1 ms 856 KB Output is correct
15 Correct 1 ms 856 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 1 ms 856 KB Output is correct
18 Correct 1 ms 696 KB Output is correct
19 Correct 1 ms 856 KB Output is correct
20 Correct 1 ms 856 KB Output is correct
21 Correct 1 ms 856 KB Output is correct
22 Correct 1 ms 856 KB Output is correct
23 Correct 1 ms 856 KB Output is correct
24 Correct 1 ms 856 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 856 KB Output is correct
28 Correct 1 ms 856 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 856 KB Output is correct
31 Correct 1 ms 856 KB Output is correct
32 Correct 1 ms 856 KB Output is correct
33 Correct 1 ms 856 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 1 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 676 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 668 KB Output is correct
14 Correct 1 ms 856 KB Output is correct
15 Correct 1 ms 856 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 1 ms 856 KB Output is correct
18 Correct 1 ms 696 KB Output is correct
19 Correct 1 ms 856 KB Output is correct
20 Correct 1 ms 856 KB Output is correct
21 Correct 1 ms 856 KB Output is correct
22 Correct 1 ms 856 KB Output is correct
23 Correct 1 ms 856 KB Output is correct
24 Correct 1 ms 856 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 856 KB Output is correct
28 Correct 1 ms 856 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 856 KB Output is correct
31 Correct 1 ms 856 KB Output is correct
32 Correct 1 ms 856 KB Output is correct
33 Correct 1 ms 856 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 1 ms 856 KB Output is correct
36 Correct 14 ms 14424 KB Output is correct
37 Correct 21 ms 21848 KB Output is correct
38 Correct 21 ms 21848 KB Output is correct
39 Correct 21 ms 21844 KB Output is correct
40 Correct 20 ms 21904 KB Output is correct
41 Correct 21 ms 21848 KB Output is correct
42 Correct 28 ms 21820 KB Output is correct
43 Correct 27 ms 21848 KB Output is correct
44 Correct 19 ms 21848 KB Output is correct
45 Correct 21 ms 21848 KB Output is correct
46 Correct 19 ms 21848 KB Output is correct
47 Correct 29 ms 21816 KB Output is correct
48 Correct 20 ms 21848 KB Output is correct
49 Correct 20 ms 22012 KB Output is correct
50 Correct 20 ms 21848 KB Output is correct
51 Correct 19 ms 21848 KB Output is correct
52 Correct 21 ms 21848 KB Output is correct
53 Correct 25 ms 21840 KB Output is correct
54 Correct 22 ms 22100 KB Output is correct
55 Correct 26 ms 21824 KB Output is correct
56 Correct 18 ms 21848 KB Output is correct
57 Correct 22 ms 21080 KB Output is correct
58 Correct 31 ms 21848 KB Output is correct
59 Correct 22 ms 21848 KB Output is correct
60 Correct 22 ms 21848 KB Output is correct
61 Correct 21 ms 21924 KB Output is correct
62 Correct 22 ms 22036 KB Output is correct
63 Correct 21 ms 21848 KB Output is correct
64 Correct 19 ms 21820 KB Output is correct
65 Correct 20 ms 21848 KB Output is correct
66 Correct 26 ms 21848 KB Output is correct
67 Correct 19 ms 21848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 518 ms 21592 KB Output is correct
2 Correct 603 ms 21848 KB Output is correct
3 Correct 661 ms 21840 KB Output is correct
4 Correct 678 ms 21848 KB Output is correct
5 Correct 663 ms 21848 KB Output is correct
6 Correct 659 ms 21840 KB Output is correct
7 Correct 694 ms 21848 KB Output is correct
8 Correct 602 ms 21848 KB Output is correct
9 Correct 585 ms 21848 KB Output is correct
10 Correct 678 ms 21848 KB Output is correct
11 Correct 621 ms 21820 KB Output is correct
12 Correct 628 ms 21812 KB Output is correct
13 Correct 641 ms 21876 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 856 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 21 ms 21840 KB Output is correct
18 Correct 20 ms 21848 KB Output is correct
19 Correct 29 ms 21840 KB Output is correct
20 Correct 27 ms 21848 KB Output is correct
21 Correct 27 ms 21816 KB Output is correct
22 Correct 21 ms 21976 KB Output is correct
23 Correct 26 ms 21848 KB Output is correct
24 Correct 26 ms 21840 KB Output is correct
25 Correct 35 ms 21840 KB Output is correct
26 Correct 20 ms 21848 KB Output is correct
27 Correct 1 ms 856 KB Output is correct
28 Correct 1 ms 856 KB Output is correct
29 Correct 1 ms 856 KB Output is correct
30 Correct 1 ms 856 KB Output is correct
31 Correct 1 ms 856 KB Output is correct
32 Correct 1 ms 856 KB Output is correct
33 Correct 1 ms 856 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 1 ms 856 KB Output is correct
36 Correct 1 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4035 ms 5464 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 676 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 668 KB Output is correct
14 Correct 1 ms 856 KB Output is correct
15 Correct 1 ms 856 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 1 ms 856 KB Output is correct
18 Correct 1 ms 696 KB Output is correct
19 Correct 1 ms 856 KB Output is correct
20 Correct 1 ms 856 KB Output is correct
21 Correct 1 ms 856 KB Output is correct
22 Correct 1 ms 856 KB Output is correct
23 Correct 1 ms 856 KB Output is correct
24 Correct 1 ms 856 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 856 KB Output is correct
28 Correct 1 ms 856 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 856 KB Output is correct
31 Correct 1 ms 856 KB Output is correct
32 Correct 1 ms 856 KB Output is correct
33 Correct 1 ms 856 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 1 ms 856 KB Output is correct
36 Correct 14 ms 14424 KB Output is correct
37 Correct 21 ms 21848 KB Output is correct
38 Correct 21 ms 21848 KB Output is correct
39 Correct 21 ms 21844 KB Output is correct
40 Correct 20 ms 21904 KB Output is correct
41 Correct 21 ms 21848 KB Output is correct
42 Correct 28 ms 21820 KB Output is correct
43 Correct 27 ms 21848 KB Output is correct
44 Correct 19 ms 21848 KB Output is correct
45 Correct 21 ms 21848 KB Output is correct
46 Correct 19 ms 21848 KB Output is correct
47 Correct 29 ms 21816 KB Output is correct
48 Correct 20 ms 21848 KB Output is correct
49 Correct 20 ms 22012 KB Output is correct
50 Correct 20 ms 21848 KB Output is correct
51 Correct 19 ms 21848 KB Output is correct
52 Correct 21 ms 21848 KB Output is correct
53 Correct 25 ms 21840 KB Output is correct
54 Correct 22 ms 22100 KB Output is correct
55 Correct 26 ms 21824 KB Output is correct
56 Correct 18 ms 21848 KB Output is correct
57 Correct 22 ms 21080 KB Output is correct
58 Correct 31 ms 21848 KB Output is correct
59 Correct 22 ms 21848 KB Output is correct
60 Correct 22 ms 21848 KB Output is correct
61 Correct 21 ms 21924 KB Output is correct
62 Correct 22 ms 22036 KB Output is correct
63 Correct 21 ms 21848 KB Output is correct
64 Correct 19 ms 21820 KB Output is correct
65 Correct 20 ms 21848 KB Output is correct
66 Correct 26 ms 21848 KB Output is correct
67 Correct 19 ms 21848 KB Output is correct
68 Correct 518 ms 21592 KB Output is correct
69 Correct 603 ms 21848 KB Output is correct
70 Correct 661 ms 21840 KB Output is correct
71 Correct 678 ms 21848 KB Output is correct
72 Correct 663 ms 21848 KB Output is correct
73 Correct 659 ms 21840 KB Output is correct
74 Correct 694 ms 21848 KB Output is correct
75 Correct 602 ms 21848 KB Output is correct
76 Correct 585 ms 21848 KB Output is correct
77 Correct 678 ms 21848 KB Output is correct
78 Correct 621 ms 21820 KB Output is correct
79 Correct 628 ms 21812 KB Output is correct
80 Correct 641 ms 21876 KB Output is correct
81 Correct 0 ms 344 KB Output is correct
82 Correct 1 ms 856 KB Output is correct
83 Correct 1 ms 856 KB Output is correct
84 Correct 21 ms 21840 KB Output is correct
85 Correct 20 ms 21848 KB Output is correct
86 Correct 29 ms 21840 KB Output is correct
87 Correct 27 ms 21848 KB Output is correct
88 Correct 27 ms 21816 KB Output is correct
89 Correct 21 ms 21976 KB Output is correct
90 Correct 26 ms 21848 KB Output is correct
91 Correct 26 ms 21840 KB Output is correct
92 Correct 35 ms 21840 KB Output is correct
93 Correct 20 ms 21848 KB Output is correct
94 Correct 1 ms 856 KB Output is correct
95 Correct 1 ms 856 KB Output is correct
96 Correct 1 ms 856 KB Output is correct
97 Correct 1 ms 856 KB Output is correct
98 Correct 1 ms 856 KB Output is correct
99 Correct 1 ms 856 KB Output is correct
100 Correct 1 ms 856 KB Output is correct
101 Correct 1 ms 856 KB Output is correct
102 Correct 1 ms 856 KB Output is correct
103 Correct 1 ms 856 KB Output is correct
104 Execution timed out 4024 ms 19544 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 326 ms 13144 KB Output is correct
2 Correct 637 ms 21848 KB Output is correct
3 Correct 610 ms 21848 KB Output is correct
4 Correct 612 ms 21828 KB Output is correct
5 Correct 682 ms 21848 KB Output is correct
6 Correct 545 ms 21944 KB Output is correct
7 Correct 643 ms 21848 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 856 KB Output is correct
13 Correct 1 ms 676 KB Output is correct
14 Correct 1 ms 856 KB Output is correct
15 Correct 1 ms 856 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 1 ms 856 KB Output is correct
18 Correct 1 ms 856 KB Output is correct
19 Correct 1 ms 856 KB Output is correct
20 Correct 1 ms 856 KB Output is correct
21 Correct 1 ms 856 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 668 KB Output is correct
24 Correct 1 ms 856 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 1 ms 856 KB Output is correct
27 Correct 1 ms 856 KB Output is correct
28 Correct 1 ms 696 KB Output is correct
29 Correct 1 ms 856 KB Output is correct
30 Correct 1 ms 856 KB Output is correct
31 Correct 1 ms 856 KB Output is correct
32 Correct 1 ms 856 KB Output is correct
33 Correct 1 ms 856 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 1112 KB Output is correct
37 Correct 1 ms 856 KB Output is correct
38 Correct 1 ms 856 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 1 ms 856 KB Output is correct
41 Correct 1 ms 856 KB Output is correct
42 Correct 1 ms 856 KB Output is correct
43 Correct 1 ms 856 KB Output is correct
44 Correct 1 ms 856 KB Output is correct
45 Correct 1 ms 856 KB Output is correct
46 Correct 14 ms 14424 KB Output is correct
47 Correct 21 ms 21848 KB Output is correct
48 Correct 21 ms 21848 KB Output is correct
49 Correct 21 ms 21844 KB Output is correct
50 Correct 20 ms 21904 KB Output is correct
51 Correct 21 ms 21848 KB Output is correct
52 Correct 28 ms 21820 KB Output is correct
53 Correct 27 ms 21848 KB Output is correct
54 Correct 19 ms 21848 KB Output is correct
55 Correct 21 ms 21848 KB Output is correct
56 Correct 19 ms 21848 KB Output is correct
57 Correct 29 ms 21816 KB Output is correct
58 Correct 20 ms 21848 KB Output is correct
59 Correct 20 ms 22012 KB Output is correct
60 Correct 20 ms 21848 KB Output is correct
61 Correct 19 ms 21848 KB Output is correct
62 Correct 21 ms 21848 KB Output is correct
63 Correct 25 ms 21840 KB Output is correct
64 Correct 22 ms 22100 KB Output is correct
65 Correct 26 ms 21824 KB Output is correct
66 Correct 18 ms 21848 KB Output is correct
67 Correct 22 ms 21080 KB Output is correct
68 Correct 31 ms 21848 KB Output is correct
69 Correct 22 ms 21848 KB Output is correct
70 Correct 22 ms 21848 KB Output is correct
71 Correct 21 ms 21924 KB Output is correct
72 Correct 22 ms 22036 KB Output is correct
73 Correct 21 ms 21848 KB Output is correct
74 Correct 19 ms 21820 KB Output is correct
75 Correct 20 ms 21848 KB Output is correct
76 Correct 26 ms 21848 KB Output is correct
77 Correct 19 ms 21848 KB Output is correct
78 Correct 518 ms 21592 KB Output is correct
79 Correct 603 ms 21848 KB Output is correct
80 Correct 661 ms 21840 KB Output is correct
81 Correct 678 ms 21848 KB Output is correct
82 Correct 663 ms 21848 KB Output is correct
83 Correct 659 ms 21840 KB Output is correct
84 Correct 694 ms 21848 KB Output is correct
85 Correct 602 ms 21848 KB Output is correct
86 Correct 585 ms 21848 KB Output is correct
87 Correct 678 ms 21848 KB Output is correct
88 Correct 621 ms 21820 KB Output is correct
89 Correct 628 ms 21812 KB Output is correct
90 Correct 641 ms 21876 KB Output is correct
91 Correct 0 ms 344 KB Output is correct
92 Correct 1 ms 856 KB Output is correct
93 Correct 1 ms 856 KB Output is correct
94 Correct 21 ms 21840 KB Output is correct
95 Correct 20 ms 21848 KB Output is correct
96 Correct 29 ms 21840 KB Output is correct
97 Correct 27 ms 21848 KB Output is correct
98 Correct 27 ms 21816 KB Output is correct
99 Correct 21 ms 21976 KB Output is correct
100 Correct 26 ms 21848 KB Output is correct
101 Correct 26 ms 21840 KB Output is correct
102 Correct 35 ms 21840 KB Output is correct
103 Correct 20 ms 21848 KB Output is correct
104 Correct 1 ms 856 KB Output is correct
105 Correct 1 ms 856 KB Output is correct
106 Correct 1 ms 856 KB Output is correct
107 Correct 1 ms 856 KB Output is correct
108 Correct 1 ms 856 KB Output is correct
109 Correct 1 ms 856 KB Output is correct
110 Correct 1 ms 856 KB Output is correct
111 Correct 1 ms 856 KB Output is correct
112 Correct 1 ms 856 KB Output is correct
113 Correct 1 ms 856 KB Output is correct
114 Execution timed out 4035 ms 5464 KB Time limit exceeded
115 Halted 0 ms 0 KB -