답안 #937820

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
937820 2024-03-04T14:27:46 Z Andrey Group Photo (JOI21_ho_t3) C++14
100 / 100
945 ms 900 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> dp(5001,INT_MAX);
vector<int> idk(5001);
int n;

void upd(int a, int x) {
    while(a <= n) {
        idk[a]+=x;
        a+=(a&(-a));
    }
}

int calc(int a) {
    int c = 0,sb = 0;
    for(int i = 12; i >= 0; i--) {
        if(c+(1 << i) <= a) {
            c+=(1 << i);
            sb+=idk[c];
        }
    }
    return sb;
}

void dude(vector<int> haha) {
    int n = haha.size()-1;
    vector<int> p(n+1);
    for(int i = 1; i <= n; i++) {
        p[haha[i]] = i;
    }
    int br = 0;
    for(int i = 0; i <= n; i++) {
        idk[i] = 0;
    }
    for(int i = n; i >= 1; i--) {
        br+=n-p[i];
        br-=calc(p[i]);
        upd(p[i],1);
        dp[n] = min(dp[n],dp[i-1]+br);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    dp[0] = 0;
    vector<int> haha(n+1);
    for(int i = 1; i <= n; i++) {
        cin >> haha[i];
    }
    for(int i = 1; i <= n; i++) {
        vector<int> bruh(1);
        for(int j = 1; j <= n; j++) {
            if(haha[j] <= i) {
                bruh.push_back(haha[j]);
            }
        }
        dude(bruh);
    }
    cout << dp[n];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 496 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 492 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 496 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 492 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 496 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 492 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 21 ms 348 KB Output is correct
32 Correct 20 ms 348 KB Output is correct
33 Correct 19 ms 596 KB Output is correct
34 Correct 20 ms 348 KB Output is correct
35 Correct 20 ms 596 KB Output is correct
36 Correct 20 ms 576 KB Output is correct
37 Correct 19 ms 580 KB Output is correct
38 Correct 19 ms 348 KB Output is correct
39 Correct 19 ms 344 KB Output is correct
40 Correct 19 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 496 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 492 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 21 ms 348 KB Output is correct
32 Correct 20 ms 348 KB Output is correct
33 Correct 19 ms 596 KB Output is correct
34 Correct 20 ms 348 KB Output is correct
35 Correct 20 ms 596 KB Output is correct
36 Correct 20 ms 576 KB Output is correct
37 Correct 19 ms 580 KB Output is correct
38 Correct 19 ms 348 KB Output is correct
39 Correct 19 ms 344 KB Output is correct
40 Correct 19 ms 348 KB Output is correct
41 Correct 934 ms 652 KB Output is correct
42 Correct 938 ms 848 KB Output is correct
43 Correct 933 ms 900 KB Output is correct
44 Correct 945 ms 848 KB Output is correct
45 Correct 929 ms 624 KB Output is correct
46 Correct 937 ms 668 KB Output is correct
47 Correct 935 ms 852 KB Output is correct
48 Correct 936 ms 848 KB Output is correct
49 Correct 935 ms 644 KB Output is correct
50 Correct 942 ms 648 KB Output is correct
51 Correct 939 ms 624 KB Output is correct
52 Correct 934 ms 612 KB Output is correct
53 Correct 935 ms 624 KB Output is correct
54 Correct 936 ms 868 KB Output is correct
55 Correct 937 ms 624 KB Output is correct