# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
709772 |
2023-03-14T11:50:52 Z |
KoD |
송신탑 (IOI22_towers) |
C++17 |
|
1162 ms |
15348 KB |
#include "towers.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <limits>
#include <iterator>
#include <tuple>
#include <cassert>
namespace kod {
using std::vector;
using std::cerr;
using std::endl;
using std::begin;
using std::end;
using std::pair;
using std::tuple;
template <class F>
struct make_fixed : private F {
explicit make_fixed(F&& f) : F(std::forward<F>(f)) {}
template <class... Args> decltype(auto) operator()(Args&&... args) const {
return F::operator()(*this, std::forward<Args>(args)...);
}
};
int N;
vector<int> H;
vector<int> par, stack;
vector<vector<int>> child;
vector<pair<int, int>> sum;
void init() {
par.assign(N, -1);
for (int i = 0; i < N; ++i) {
int j = -1;
while (!stack.empty() and H[stack.back()] < H[i]) {
j = stack.back();
stack.pop_back();
}
if (j != -1) par[j] = i;
if (!stack.empty()) par[i] = stack.back();
stack.push_back(i);
}
int root = -1;
child.resize(N);
for (int i = 0; i < N; ++i) {
if (par[i] == -1) root = i;
else child[par[i]].push_back(i);
}
make_fixed([&](auto&& dfs, const int u) -> int {
int min = H[u];
for (const int v : child[u]) {
const int m = dfs(v);
min = std::min(min, m);
sum.emplace_back(H[u] - m, 1);
sum.emplace_back(H[v] - m, -1);
}
return min;
})(root);
std::sort(begin(sum), end(sum));
for (int i = (int)sum.size() - 1; i > 0; --i) {
sum[i - 1].second += sum[i].second;
}
}
int solve(const int L, const int R, const int D) {
assert(L == 0 and R == N - 1);
return std::max(1, std::lower_bound(begin(sum), end(sum), pair(D, 0))->second);
}
}
void init(int N, std::vector<int> H) {
kod::N = N;
kod::H = H;
kod::init();
}
int max_towers(int L, int R, int D) {
return kod::solve(L, R, D);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
15348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
49 ms |
15104 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
348 ms |
2336 KB |
Output is correct |
2 |
Correct |
937 ms |
8364 KB |
Output is correct |
3 |
Correct |
836 ms |
8464 KB |
Output is correct |
4 |
Correct |
943 ms |
7852 KB |
Output is correct |
5 |
Correct |
992 ms |
7920 KB |
Output is correct |
6 |
Correct |
1020 ms |
7852 KB |
Output is correct |
7 |
Correct |
1153 ms |
7852 KB |
Output is correct |
8 |
Correct |
1051 ms |
14132 KB |
Output is correct |
9 |
Correct |
1162 ms |
14504 KB |
Output is correct |
10 |
Correct |
1127 ms |
12328 KB |
Output is correct |
11 |
Correct |
947 ms |
12948 KB |
Output is correct |
12 |
Correct |
50 ms |
8468 KB |
Output is correct |
13 |
Correct |
44 ms |
7832 KB |
Output is correct |
14 |
Correct |
34 ms |
7952 KB |
Output is correct |
15 |
Correct |
25 ms |
14608 KB |
Output is correct |
16 |
Correct |
37 ms |
13700 KB |
Output is correct |
17 |
Correct |
40 ms |
8204 KB |
Output is correct |
18 |
Correct |
36 ms |
8464 KB |
Output is correct |
19 |
Correct |
37 ms |
8452 KB |
Output is correct |
20 |
Correct |
41 ms |
7956 KB |
Output is correct |
21 |
Correct |
38 ms |
7952 KB |
Output is correct |
22 |
Correct |
37 ms |
7956 KB |
Output is correct |
23 |
Correct |
45 ms |
7956 KB |
Output is correct |
24 |
Correct |
37 ms |
14108 KB |
Output is correct |
25 |
Correct |
30 ms |
14596 KB |
Output is correct |
26 |
Correct |
33 ms |
12308 KB |
Output is correct |
27 |
Correct |
33 ms |
14232 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
592 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
1 ms |
512 KB |
Output is correct |
37 |
Correct |
1 ms |
464 KB |
Output is correct |
38 |
Correct |
2 ms |
464 KB |
Output is correct |
39 |
Correct |
1 ms |
464 KB |
Output is correct |
40 |
Correct |
1 ms |
464 KB |
Output is correct |
41 |
Correct |
1 ms |
592 KB |
Output is correct |
42 |
Correct |
1 ms |
464 KB |
Output is correct |
43 |
Correct |
1 ms |
552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
15348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |