답안 #1046767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046767 2024-08-06T22:14:25 Z Trent 송신탑 (IOI22_towers) C++17
23 / 100
4000 ms 6988 KB
#include "towers.h"
#include "bits/stdc++.h";
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct pii{int a, b;};

const int MN = 1e5 + 10;
int h[MN], n;
void init(int N, std::vector<int> H) {
  n = N;
  forR(i, N) h[i] = H[i];
}

int l[MN], r[MN], cmax[MN];
struct event{int ti, i, ty;}; // 0: L, 1: i
int bit[MN];
void upd(int i, int to) {
  bit[i] = max(bit[i], to);
}
int qu(int i) {
  int ret = bit[i];
  for(; i >= 0; --i) ret = max(ret, bit[i]);
  return ret;
}
int max_towers(int L, int R, int D) {
  vector<int> mono;
  REP(i, L, R+1) {
    int ind = upper_bound(all(mono), h[i] + D, [](int a, int b){return a > h[b];}) - mono.begin() - 1;
    l[i] = ind == -1 ? L-1 : mono[ind];
    while(!mono.empty() && h[mono.back()] <= h[i]) mono.pop_back();
    mono.push_back(i);
  }
  mono.clear();
  for(int i = R; i >= L; --i) {
    int ind = upper_bound(all(mono), h[i] + D, [](int a, int b){return a > h[b];}) - mono.begin() - 1;
    r[i] = ind == -1 ? R + 1 : mono[ind];
    while(!mono.empty() && h[mono.back()] <= h[i]) mono.pop_back();
    mono.push_back(i);
  }
  vector<event> evs;
  REP(i, L, R+1) {
    evs.push_back({l[i], i, 0});
    evs.push_back({i, i, 1});
  }
  sort(all(evs), [](event& a, event& b){return a.ti < b.ti || a.ti == b.ti && a.ty == 0 && b.ty != 0;});
  for(auto [ti, i, ty] : evs) {
    if(ty == 0) {
      cmax[i] = qu(i) + 1;
    } else {
      upd(r[i] + 1, cmax[i]);
    }
  }
  return qu(MN - 1);
}

Compilation message

towers.cpp:2:25: warning: extra tokens at end of #include directive
    2 | #include "bits/stdc++.h";
      |                         ^
towers.cpp: In lambda function:
towers.cpp:52:89: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   52 |   sort(all(evs), [](event& a, event& b){return a.ti < b.ti || a.ti == b.ti && a.ty == 0 && b.ty != 0;});
      |                                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4049 ms 4640 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 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 2 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 2 ms 600 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 2 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 2 ms 600 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 138 ms 1880 KB Output is correct
37 Correct 1338 ms 3152 KB Output is correct
38 Correct 537 ms 2248 KB Output is correct
39 Correct 509 ms 2512 KB Output is correct
40 Correct 151 ms 2248 KB Output is correct
41 Correct 2623 ms 6476 KB Output is correct
42 Correct 45 ms 1624 KB Output is correct
43 Correct 1947 ms 4120 KB Output is correct
44 Correct 406 ms 2000 KB Output is correct
45 Correct 32 ms 1368 KB Output is correct
46 Correct 48 ms 1368 KB Output is correct
47 Correct 533 ms 3152 KB Output is correct
48 Correct 960 ms 2512 KB Output is correct
49 Correct 153 ms 1736 KB Output is correct
50 Correct 264 ms 2532 KB Output is correct
51 Correct 1701 ms 4048 KB Output is correct
52 Correct 2780 ms 5196 KB Output is correct
53 Correct 2759 ms 5196 KB Output is correct
54 Correct 2782 ms 5196 KB Output is correct
55 Correct 2795 ms 6988 KB Output is correct
56 Correct 2844 ms 5452 KB Output is correct
57 Correct 2600 ms 5972 KB Output is correct
58 Correct 2778 ms 5708 KB Output is correct
59 Correct 2855 ms 5196 KB Output is correct
60 Correct 2776 ms 5196 KB Output is correct
61 Correct 2772 ms 6220 KB Output is correct
62 Correct 2769 ms 5196 KB Output is correct
63 Correct 2796 ms 5708 KB Output is correct
64 Correct 2757 ms 5452 KB Output is correct
65 Correct 2787 ms 5452 KB Output is correct
66 Correct 2790 ms 6860 KB Output is correct
67 Correct 2768 ms 6220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4059 ms 4740 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4066 ms 2328 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 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 2 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 2 ms 600 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 138 ms 1880 KB Output is correct
37 Correct 1338 ms 3152 KB Output is correct
38 Correct 537 ms 2248 KB Output is correct
39 Correct 509 ms 2512 KB Output is correct
40 Correct 151 ms 2248 KB Output is correct
41 Correct 2623 ms 6476 KB Output is correct
42 Correct 45 ms 1624 KB Output is correct
43 Correct 1947 ms 4120 KB Output is correct
44 Correct 406 ms 2000 KB Output is correct
45 Correct 32 ms 1368 KB Output is correct
46 Correct 48 ms 1368 KB Output is correct
47 Correct 533 ms 3152 KB Output is correct
48 Correct 960 ms 2512 KB Output is correct
49 Correct 153 ms 1736 KB Output is correct
50 Correct 264 ms 2532 KB Output is correct
51 Correct 1701 ms 4048 KB Output is correct
52 Correct 2780 ms 5196 KB Output is correct
53 Correct 2759 ms 5196 KB Output is correct
54 Correct 2782 ms 5196 KB Output is correct
55 Correct 2795 ms 6988 KB Output is correct
56 Correct 2844 ms 5452 KB Output is correct
57 Correct 2600 ms 5972 KB Output is correct
58 Correct 2778 ms 5708 KB Output is correct
59 Correct 2855 ms 5196 KB Output is correct
60 Correct 2776 ms 5196 KB Output is correct
61 Correct 2772 ms 6220 KB Output is correct
62 Correct 2769 ms 5196 KB Output is correct
63 Correct 2796 ms 5708 KB Output is correct
64 Correct 2757 ms 5452 KB Output is correct
65 Correct 2787 ms 5452 KB Output is correct
66 Correct 2790 ms 6860 KB Output is correct
67 Correct 2768 ms 6220 KB Output is correct
68 Execution timed out 4059 ms 4740 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4049 ms 4640 KB Time limit exceeded
2 Halted 0 ms 0 KB -