답안 #950734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950734 2024-03-20T15:53:37 Z vjudge1 Chorus (JOI23_chorus) C++17
40 / 100
7000 ms 268844 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
#define int ll
using ll = long long;
using ld = long double;  // or double, if TL is tight
using str = string; 
using ii = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;

struct AIB {
    int n;
    vi V;

    AIB(int N) : n(N + 1), V(N + 1, 0) {}

    void update(int p, int v) {
        ++p;
        while(p < n) {
            V[p] += v;
            p += p & -p;
        }
    }
    
    int query(int p) {
        ++p;
        int re = 0;
        while(p) {
            re += V[p];
            p -= p & - p;
        }
        return re;
    }

    int query(int st, int dr) { return query(dr) - query(st - 1); }
};

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    const int INF = 1e12;

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vi A, B;
    for(int i = 0; i < 2 * n; ++i)
        if(s[i] == 'A') A.push_back(i);
        else B.push_back(i);
    vector<vi> Cost(n, vi(n, 0)); /// (st, dr) costul pt a le cupla
    for(int st = 0; st < n; ++st) {
        AIB S(2 * n);
        for(int i = st; i < n; ++i) {
            S.update(B[i], 1);
            S.update(A[i], 1);
        }
        int re = 0;
        for(int dr = st; dr < n; ++dr) {
            S.update(A[dr], -1);
            re += S.query(A[dr]);
            Cost[st][dr] = re;
        }
    }
    vector<vi> DP(k, vi(n, 1e12));
    for(int i = 0; i < n; ++i)
        DP[0][i] = Cost[0][i];
    for(int i = 1; i < k; ++i) {
        for(int j = 0; j < n; ++j) {
            for(int w = 0; w < j; ++w) {
                DP[i][j] = min(DP[i][j], DP[i - 1][w] + Cost[w + 1][j]);
            }
        }
    }
    cout << DP.back()[n - 1] << "\n";
    return 0;
}

Compilation message

chorus.cpp: In function 'int main()':
chorus.cpp:49:15: warning: unused variable 'INF' [-Wunused-variable]
   49 |     const int INF = 1e12;
      |               ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 18 ms 2648 KB Output is correct
19 Correct 48 ms 3292 KB Output is correct
20 Correct 4 ms 2400 KB Output is correct
21 Correct 3 ms 2396 KB Output is correct
22 Correct 79 ms 4244 KB Output is correct
23 Correct 77 ms 4440 KB Output is correct
24 Correct 4 ms 2428 KB Output is correct
25 Correct 76 ms 4188 KB Output is correct
26 Correct 70 ms 3932 KB Output is correct
27 Correct 37 ms 3088 KB Output is correct
28 Correct 28 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 18 ms 2648 KB Output is correct
19 Correct 48 ms 3292 KB Output is correct
20 Correct 4 ms 2400 KB Output is correct
21 Correct 3 ms 2396 KB Output is correct
22 Correct 79 ms 4244 KB Output is correct
23 Correct 77 ms 4440 KB Output is correct
24 Correct 4 ms 2428 KB Output is correct
25 Correct 76 ms 4188 KB Output is correct
26 Correct 70 ms 3932 KB Output is correct
27 Correct 37 ms 3088 KB Output is correct
28 Correct 28 ms 2908 KB Output is correct
29 Execution timed out 7086 ms 268844 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 18 ms 2648 KB Output is correct
19 Correct 48 ms 3292 KB Output is correct
20 Correct 4 ms 2400 KB Output is correct
21 Correct 3 ms 2396 KB Output is correct
22 Correct 79 ms 4244 KB Output is correct
23 Correct 77 ms 4440 KB Output is correct
24 Correct 4 ms 2428 KB Output is correct
25 Correct 76 ms 4188 KB Output is correct
26 Correct 70 ms 3932 KB Output is correct
27 Correct 37 ms 3088 KB Output is correct
28 Correct 28 ms 2908 KB Output is correct
29 Execution timed out 7086 ms 268844 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 18 ms 2648 KB Output is correct
19 Correct 48 ms 3292 KB Output is correct
20 Correct 4 ms 2400 KB Output is correct
21 Correct 3 ms 2396 KB Output is correct
22 Correct 79 ms 4244 KB Output is correct
23 Correct 77 ms 4440 KB Output is correct
24 Correct 4 ms 2428 KB Output is correct
25 Correct 76 ms 4188 KB Output is correct
26 Correct 70 ms 3932 KB Output is correct
27 Correct 37 ms 3088 KB Output is correct
28 Correct 28 ms 2908 KB Output is correct
29 Execution timed out 7086 ms 268844 KB Time limit exceeded
30 Halted 0 ms 0 KB -