Submission #1065830

# Submission time Handle Problem Language Result Execution time Memory
1065830 2024-08-19T12:05:07 Z j_vdd16 Radio Towers (IOI22_towers) C++17
14 / 100
681 ms 2040 KB
#include "towers.h"

#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

//#define int long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;

typedef uint64_t u64;
typedef int64_t i64;

int n;
vi h;
vi minPref;

int getMax(int l, int r) {
    int best = 0;
    for (int i = l; i <= r; i++) {
        best = max(best, h[i]);
    }

    return best;
}

void init(int N, std::vector<int> H) {
    //all H[i] are different
    //dp[i] = max of 1 and all dp[j] over j s.t. j < i && maxH(j, i) - D >= max(H[i], H[j])

    //D = 1
    //H = 1, 2, 6, 4, 5, 3, 7
    //dp= 1, 1, 1, 2, 2, 3, 1

    n = N;
    h = H;

    if (n == 1) return;

    vb isMinimum(n);
    loop(i, n) {
        if (i == 0) {
            isMinimum[i] = h[i] < h[i + 1];
        }
        else if (i == n - 1) {
            isMinimum[i] = h[i] < h[i - 1];
        }
        else {
            isMinimum[i] = h[i] < h[i + 1] && h[i] < h[i - 1];
        }
    }

    minPref = vi(n + 1);
    for (int i = 1; i < n; i++) {
        minPref[i + 1] = minPref[i] + isMinimum[i];
    }
}

int max_towers(int L, int R, int D) {
    if (L == R) {
        return 1;
    }

    int res = minPref[R] - minPref[L + 1];
    if (L + 1 < n) {
        res += h[L] < h[L + 1];
    }
    else {
        res++;
    }
    if (R - 1 >= 0) {
        res += h[R] < h[R - 1];
    }
    else {
        res++;
    }

    return res;


    // vi dp(n);
    // int res = 0;
    // for (int i = L; i <= R; i++) {
    //     dp[i] = 1;
    //     for (int j = L; j < i; j++) {
    //         if (getMax(j + 1, i - 1) - D >= max(h[i], h[j])) {
    //             dp[i] = max(dp[i], dp[j] + 1);
    //         }
    //     }

    //     res = max(res, dp[i]);
    // }

    // return res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 309 ms 1620 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 489 ms 1880 KB Output is correct
2 Correct 628 ms 1880 KB Output is correct
3 Correct 681 ms 1880 KB Output is correct
4 Correct 632 ms 1880 KB Output is correct
5 Correct 627 ms 1880 KB Output is correct
6 Correct 658 ms 1880 KB Output is correct
7 Correct 564 ms 1880 KB Output is correct
8 Correct 592 ms 1880 KB Output is correct
9 Correct 612 ms 1880 KB Output is correct
10 Correct 614 ms 1880 KB Output is correct
11 Correct 604 ms 1880 KB Output is correct
12 Correct 569 ms 1860 KB Output is correct
13 Correct 525 ms 1964 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 12 ms 1856 KB Output is correct
18 Correct 12 ms 1856 KB Output is correct
19 Correct 10 ms 1780 KB Output is correct
20 Correct 9 ms 1880 KB Output is correct
21 Correct 9 ms 1856 KB Output is correct
22 Correct 17 ms 1880 KB Output is correct
23 Correct 10 ms 1880 KB Output is correct
24 Correct 9 ms 1880 KB Output is correct
25 Correct 12 ms 1880 KB Output is correct
26 Correct 14 ms 2040 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 0 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 154 ms 780 KB 1st lines differ - on the 1st token, expected: '7197', found: '8004'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 309 ms 1620 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -