답안 #798935

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798935 2023-07-31T07:41:14 Z finn__ Chorus (JOI23_chorus) C++17
40 / 100
69 ms 2292 KB
#include <bits/stdc++.h>
using namespace std;

struct linear_fn
{
    int64_t m, t;
    linear_fn(int64_t m, int64_t t) { this->m = m, this->t = t; }
    int64_t operator()(int64_t x) { return m * x + t; }
    bool intersects_earlier(linear_fn const &f, linear_fn const &g)
    {
        return (__int128_t)(f.t - t) * (m - g.m) < (__int128_t)(m - f.m) * (g.t - t);
    }
};

constexpr size_t N = 501;

int64_t p[N], b[N], f[N][N], j_[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    size_t n, k;
    string s;
    cin >> n >> k >> s;

    for (size_t i = 1, j = 1, l = 1; i <= n << 1; ++i)
    {
        if (s[i - 1] == 'B')
            b[j++] = i;
        else
            p[l++] = j;
    }

    for (size_t i = 1; i <= n; ++i)
        j_[i] = max<int64_t>(i, lower_bound(p + 1, p + n + 1, i) - p);

    for (size_t i = 1; i <= n; ++i)
        p[i] += p[i - 1];

    for (size_t i = 0; i < N; ++i)
        fill(f[i], f[i] + N, INT64_MAX);
    f[0][0] = 0;

    for (size_t l = 1; l <= k; ++l)
        for (int64_t i = 1; i <= n; ++i)
            for (int64_t j = 0; j < i; ++j)
                if (f[l - 1][j] != INT64_MAX)
                {
                    int64_t j__ = min(i + 1, j_[j + 1]),
                            val = f[l - 1][j] + p[i] - p[j__ - 1] - (i - j__ + 1) * (j + 1);
                    if (val < f[l][i])
                        f[l][i] = val;
                }

    // int64_t a = 0, b = 1LL << 6;
    // while (a < b)
    // {
    //     int64_t lambda = (a + b) / 2;
    //     auto [val, used] = cht(lambda);
    //     if (used > k)
    //         a = lambda + 1;
    //     else
    //         b = lambda;
    // }

    cout << f[k][n] << '\n';
}

Compilation message

chorus.cpp: In function 'int main()':
chorus.cpp:47:31: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int64_t i = 1; i <= n; ++i)
      |                             ~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 1 ms 2248 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 1 ms 2244 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2248 KB Output is correct
12 Correct 1 ms 2260 KB Output is correct
13 Correct 2 ms 2248 KB Output is correct
14 Correct 1 ms 2260 KB Output is correct
15 Correct 1 ms 2260 KB Output is correct
16 Correct 1 ms 2288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 1 ms 2248 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 1 ms 2244 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2248 KB Output is correct
12 Correct 1 ms 2260 KB Output is correct
13 Correct 2 ms 2248 KB Output is correct
14 Correct 1 ms 2260 KB Output is correct
15 Correct 1 ms 2260 KB Output is correct
16 Correct 1 ms 2288 KB Output is correct
17 Correct 2 ms 2248 KB Output is correct
18 Correct 18 ms 2292 KB Output is correct
19 Correct 42 ms 2260 KB Output is correct
20 Correct 1 ms 2260 KB Output is correct
21 Correct 2 ms 2260 KB Output is correct
22 Correct 69 ms 2272 KB Output is correct
23 Correct 63 ms 2272 KB Output is correct
24 Correct 3 ms 2260 KB Output is correct
25 Correct 62 ms 2280 KB Output is correct
26 Correct 55 ms 2260 KB Output is correct
27 Correct 29 ms 2240 KB Output is correct
28 Correct 29 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 1 ms 2248 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 1 ms 2244 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2248 KB Output is correct
12 Correct 1 ms 2260 KB Output is correct
13 Correct 2 ms 2248 KB Output is correct
14 Correct 1 ms 2260 KB Output is correct
15 Correct 1 ms 2260 KB Output is correct
16 Correct 1 ms 2288 KB Output is correct
17 Correct 2 ms 2248 KB Output is correct
18 Correct 18 ms 2292 KB Output is correct
19 Correct 42 ms 2260 KB Output is correct
20 Correct 1 ms 2260 KB Output is correct
21 Correct 2 ms 2260 KB Output is correct
22 Correct 69 ms 2272 KB Output is correct
23 Correct 63 ms 2272 KB Output is correct
24 Correct 3 ms 2260 KB Output is correct
25 Correct 62 ms 2280 KB Output is correct
26 Correct 55 ms 2260 KB Output is correct
27 Correct 29 ms 2240 KB Output is correct
28 Correct 29 ms 2260 KB Output is correct
29 Runtime error 1 ms 468 KB Execution killed with signal 11
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 1 ms 2248 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 1 ms 2244 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2248 KB Output is correct
12 Correct 1 ms 2260 KB Output is correct
13 Correct 2 ms 2248 KB Output is correct
14 Correct 1 ms 2260 KB Output is correct
15 Correct 1 ms 2260 KB Output is correct
16 Correct 1 ms 2288 KB Output is correct
17 Correct 2 ms 2248 KB Output is correct
18 Correct 18 ms 2292 KB Output is correct
19 Correct 42 ms 2260 KB Output is correct
20 Correct 1 ms 2260 KB Output is correct
21 Correct 2 ms 2260 KB Output is correct
22 Correct 69 ms 2272 KB Output is correct
23 Correct 63 ms 2272 KB Output is correct
24 Correct 3 ms 2260 KB Output is correct
25 Correct 62 ms 2280 KB Output is correct
26 Correct 55 ms 2260 KB Output is correct
27 Correct 29 ms 2240 KB Output is correct
28 Correct 29 ms 2260 KB Output is correct
29 Runtime error 1 ms 468 KB Execution killed with signal 11
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 1 ms 2248 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 1 ms 2244 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2248 KB Output is correct
12 Correct 1 ms 2260 KB Output is correct
13 Correct 2 ms 2248 KB Output is correct
14 Correct 1 ms 2260 KB Output is correct
15 Correct 1 ms 2260 KB Output is correct
16 Correct 1 ms 2288 KB Output is correct
17 Correct 2 ms 2248 KB Output is correct
18 Correct 18 ms 2292 KB Output is correct
19 Correct 42 ms 2260 KB Output is correct
20 Correct 1 ms 2260 KB Output is correct
21 Correct 2 ms 2260 KB Output is correct
22 Correct 69 ms 2272 KB Output is correct
23 Correct 63 ms 2272 KB Output is correct
24 Correct 3 ms 2260 KB Output is correct
25 Correct 62 ms 2280 KB Output is correct
26 Correct 55 ms 2260 KB Output is correct
27 Correct 29 ms 2240 KB Output is correct
28 Correct 29 ms 2260 KB Output is correct
29 Runtime error 1 ms 468 KB Execution killed with signal 11
30 Halted 0 ms 0 KB -