Submission #950730

# Submission time Handle Problem Language Result Execution time Memory
950730 2024-03-20T15:51:58 Z vjudge1 Chorus (JOI23_chorus) C++17
40 / 100
7000 ms 189976 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);
        }
        for(int dr = st; dr < n; ++dr) {
            S.update(A[dr], -1);
            int re = 0;
            for(int w = st; w <= dr; ++w) {
                re += S.query(A[w]);
            }
            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;
      |               ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 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 0 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 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 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 0 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 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 7 ms 604 KB Output is correct
18 Correct 167 ms 2796 KB Output is correct
19 Correct 188 ms 3416 KB Output is correct
20 Correct 145 ms 2436 KB Output is correct
21 Correct 134 ms 2400 KB Output is correct
22 Correct 206 ms 4404 KB Output is correct
23 Correct 211 ms 4180 KB Output is correct
24 Correct 149 ms 2436 KB Output is correct
25 Correct 242 ms 4220 KB Output is correct
26 Correct 203 ms 3968 KB Output is correct
27 Correct 169 ms 2952 KB Output is correct
28 Correct 169 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 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 0 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 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 7 ms 604 KB Output is correct
18 Correct 167 ms 2796 KB Output is correct
19 Correct 188 ms 3416 KB Output is correct
20 Correct 145 ms 2436 KB Output is correct
21 Correct 134 ms 2400 KB Output is correct
22 Correct 206 ms 4404 KB Output is correct
23 Correct 211 ms 4180 KB Output is correct
24 Correct 149 ms 2436 KB Output is correct
25 Correct 242 ms 4220 KB Output is correct
26 Correct 203 ms 3968 KB Output is correct
27 Correct 169 ms 2952 KB Output is correct
28 Correct 169 ms 2936 KB Output is correct
29 Execution timed out 7016 ms 189976 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 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 0 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 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 7 ms 604 KB Output is correct
18 Correct 167 ms 2796 KB Output is correct
19 Correct 188 ms 3416 KB Output is correct
20 Correct 145 ms 2436 KB Output is correct
21 Correct 134 ms 2400 KB Output is correct
22 Correct 206 ms 4404 KB Output is correct
23 Correct 211 ms 4180 KB Output is correct
24 Correct 149 ms 2436 KB Output is correct
25 Correct 242 ms 4220 KB Output is correct
26 Correct 203 ms 3968 KB Output is correct
27 Correct 169 ms 2952 KB Output is correct
28 Correct 169 ms 2936 KB Output is correct
29 Execution timed out 7016 ms 189976 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 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 0 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 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 7 ms 604 KB Output is correct
18 Correct 167 ms 2796 KB Output is correct
19 Correct 188 ms 3416 KB Output is correct
20 Correct 145 ms 2436 KB Output is correct
21 Correct 134 ms 2400 KB Output is correct
22 Correct 206 ms 4404 KB Output is correct
23 Correct 211 ms 4180 KB Output is correct
24 Correct 149 ms 2436 KB Output is correct
25 Correct 242 ms 4220 KB Output is correct
26 Correct 203 ms 3968 KB Output is correct
27 Correct 169 ms 2952 KB Output is correct
28 Correct 169 ms 2936 KB Output is correct
29 Execution timed out 7016 ms 189976 KB Time limit exceeded
30 Halted 0 ms 0 KB -