답안 #1076638

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1076638 2024-08-26T15:11:37 Z vjudge1 송신탑 (IOI22_towers) C++17
23 / 100
4000 ms 11344 KB
#include "towers.h"
#include <bits/stdc++.h>


using namespace std;

using vi = vector<int>;
const int INF = 1e9;

int n;
vi H;

vi St, Dr;
vi DeltaSt, DeltaDr;

struct RMQ {
    int n;
    vector<vi> A;
    RMQ(vi V0) : n((int)V0.size()) {
        A.push_back(V0);
        for(int k = 1; (1 << k) <= n; ++k) {
            A.push_back(A.back());
            for(int i = 0; i < n; ++i) {
                if(i + (1 << (k - 1)) < n)
                    A[k][i] = max(A[k][i], A[k - 1][i + (1 << (k - 1))]);
            }
        }
    }

    int query(int l, int r) {
        int d = 31 - __builtin_clz(r - l + 1);
        return max(A[d][l], A[d][r - (1 << d) + 1]);
    }
};

pair<vi, vi> descomp(vi A) {
    RMQ R(A);
    vi Ant(n, -1);
    vi Delta(n, INF); /// cel mai mare delta posibil
    stack<int> S;
    for(int i = 0; i < n; ++i) {
        while(!S.empty() && A[S.top()] > A[i]) {
            S.pop();
        }
        if(!S.empty()) {
            Ant[i] = S.top();
            Delta[i] = R.query(S.top(), i) - A[i];
        }
        S.push(i);
    }
    return make_pair(Ant, Delta);
}

vi S;


void init(int N0, vi H0) {
    n = N0;
    H = H0;

    tie(St, DeltaSt) = descomp(H);
    reverse(H.begin(), H.end());
    tie(Dr, DeltaDr) = descomp(H);
    reverse(H.begin(), H.end());
    reverse(Dr.begin(), Dr.end());
    reverse(DeltaDr.begin(), DeltaDr.end());
    for(auto &it : Dr) 
        it = n - it - 1;
    S.resize(n);
    for(int i = 0; i < n; ++i) {
        S[i] = min(DeltaSt[i], DeltaDr[i]);
    }
 //   cout << "St: ";
 //   for(auto it : St) cout << it << " ";
 //   cout << "\n";
 //   cout << "DeltaSt: ";
 //   for(auto it : DeltaSt) cout << it << " ";
 //   cout << "\n";
 //   cout << "Dr: ";
 //   for(auto it : Dr) cout << it << " ";
 //   cout << "\n";
 //   cout << "DeltaDr: ";
 //   for(auto it : DeltaDr) cout << it << " ";
 //   cout << "\n";
}

int max_towers(int l, int r, int D) {
    vi Sol;
    for(int i = l; i <= r; ++i) {
        if(S[i] >= D) {
            Sol.push_back(i);
        }
    }
    if(Sol.empty()) {
        ///poate gasim un SolDr >= D si dupa un SolSt >= D
        int tip = 0;
        for(int i = l; i <= r; ++i) {
            if(DeltaDr[i] >= D) {
                if(tip == 0) {
                    tip = 1;
                    continue;
                }
            }
            if(DeltaSt[i] >= D && tip == 1) {
                tip = 2;
                continue;
            }
        }
        if(tip == 2) return 2;
        return 1;
    }
    int found_st = 0, found_dr = 0;
    for(int i = l; i < Sol[0]; ++i)
        if(DeltaDr[i] >= D) found_st = 1;
    for(int i = Sol.back() + 1; i <= r; ++i)
        if(DeltaSt[i] >= D) found_dr = 1;
    return int(Sol.size()) + found_st + found_dr;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2429 ms 6592 KB Output is correct
2 Execution timed out 4011 ms 11272 KB Time limit exceeded
3 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 0 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 0 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 416 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 564 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 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 0 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 0 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 416 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 564 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 16 ms 7000 KB Output is correct
37 Correct 28 ms 10816 KB Output is correct
38 Correct 21 ms 10816 KB Output is correct
39 Correct 26 ms 10816 KB Output is correct
40 Correct 22 ms 10788 KB Output is correct
41 Correct 37 ms 10952 KB Output is correct
42 Correct 20 ms 10808 KB Output is correct
43 Correct 18 ms 10816 KB Output is correct
44 Correct 26 ms 11328 KB Output is correct
45 Correct 25 ms 11040 KB Output is correct
46 Correct 35 ms 11044 KB Output is correct
47 Correct 37 ms 10788 KB Output is correct
48 Correct 21 ms 10808 KB Output is correct
49 Correct 20 ms 10816 KB Output is correct
50 Correct 24 ms 11300 KB Output is correct
51 Correct 24 ms 10852 KB Output is correct
52 Correct 25 ms 10768 KB Output is correct
53 Correct 23 ms 10788 KB Output is correct
54 Correct 25 ms 10816 KB Output is correct
55 Correct 27 ms 11200 KB Output is correct
56 Correct 20 ms 11236 KB Output is correct
57 Correct 26 ms 10400 KB Output is correct
58 Correct 24 ms 10956 KB Output is correct
59 Correct 24 ms 10816 KB Output is correct
60 Correct 26 ms 10840 KB Output is correct
61 Correct 25 ms 10788 KB Output is correct
62 Correct 30 ms 10796 KB Output is correct
63 Correct 26 ms 10864 KB Output is correct
64 Correct 26 ms 10828 KB Output is correct
65 Correct 24 ms 11344 KB Output is correct
66 Correct 23 ms 11260 KB Output is correct
67 Correct 28 ms 11300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4072 ms 10856 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2468 ms 2744 KB Output is correct
2 Execution timed out 4091 ms 10804 KB Time limit exceeded
3 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 0 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 0 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 416 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 564 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 16 ms 7000 KB Output is correct
37 Correct 28 ms 10816 KB Output is correct
38 Correct 21 ms 10816 KB Output is correct
39 Correct 26 ms 10816 KB Output is correct
40 Correct 22 ms 10788 KB Output is correct
41 Correct 37 ms 10952 KB Output is correct
42 Correct 20 ms 10808 KB Output is correct
43 Correct 18 ms 10816 KB Output is correct
44 Correct 26 ms 11328 KB Output is correct
45 Correct 25 ms 11040 KB Output is correct
46 Correct 35 ms 11044 KB Output is correct
47 Correct 37 ms 10788 KB Output is correct
48 Correct 21 ms 10808 KB Output is correct
49 Correct 20 ms 10816 KB Output is correct
50 Correct 24 ms 11300 KB Output is correct
51 Correct 24 ms 10852 KB Output is correct
52 Correct 25 ms 10768 KB Output is correct
53 Correct 23 ms 10788 KB Output is correct
54 Correct 25 ms 10816 KB Output is correct
55 Correct 27 ms 11200 KB Output is correct
56 Correct 20 ms 11236 KB Output is correct
57 Correct 26 ms 10400 KB Output is correct
58 Correct 24 ms 10956 KB Output is correct
59 Correct 24 ms 10816 KB Output is correct
60 Correct 26 ms 10840 KB Output is correct
61 Correct 25 ms 10788 KB Output is correct
62 Correct 30 ms 10796 KB Output is correct
63 Correct 26 ms 10864 KB Output is correct
64 Correct 26 ms 10828 KB Output is correct
65 Correct 24 ms 11344 KB Output is correct
66 Correct 23 ms 11260 KB Output is correct
67 Correct 28 ms 11300 KB Output is correct
68 Execution timed out 4072 ms 10856 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2429 ms 6592 KB Output is correct
2 Execution timed out 4011 ms 11272 KB Time limit exceeded
3 Halted 0 ms 0 KB -