답안 #939969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939969 2024-03-07T02:44:22 Z Marco_Escandon Group Photo (JOI21_ho_t3) C++11
100 / 100
905 ms 196528 KB
#include<bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(9);
#pragma GCC optimize("Ofast")
typedef long long ll;
struct Fenwick_tree {
    ll n;
    vector<ll> T;
    void update(ll a, ll b) {
        for(; a<n; a+=(a&(-a)))
            T[a]+=b;
    }
    ll query(ll a) {
        ll ans=0;
        for(; a>0; a-=(a&(-a)))
            ans+=T[a];
        return ans;
    }
    ll query(ll a, ll b) { return query(b) - query(a-1); }

    Fenwick_tree(ll N){
        n = N * 2;
        T.assign(n, 0);
    }
};
int main()
{
    optimizar_io
    ll n;
    cin>>n;
    ll cad[n+1];
    for(int i=1; i<=n; i++)
        cin>>cad[i];
    ll dp1[n+1][n+1];
    ll dp[n+1];
    for(int i=1; i<=n; i++)
    {
        Fenwick_tree asd(n+5);
        dp[i]=1e9;
        ll cont=0;
        for(int j=0; j<=n; j++)
        {
            dp1[i][j]=0;
        }
        for(int j=1; j<=n; j++)
        {
            if(cad[j]<i) continue;
            //if(cad[j]==4){ cout<<asd.query(i,cad[j])<<" "<<asd.query(cad[j],n)<<" "<<(cad[j]-i)-asd.query(i,cad[j])<<"\n";}
            dp1[i][cad[j]]+=asd.query(i,cad[j]);
            dp1[i][cad[j]]+=asd.query(cad[j],n);
            dp1[i][cad[j]]-=(cad[j]-i)-asd.query(i,cad[j]);
            asd.update(cad[j],1);
        }
        for(int j=1; j<=n; j++)
            dp1[i][j]+=dp1[i][j-1];           
    }
    dp[0]=0;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=i; j++)
        {
            dp[i]=min(dp[i],dp[j-1]+dp1[j][i]);
        }
    }
    cout<<dp[n];
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:40:12: warning: unused variable 'cont' [-Wunused-variable]
   40 |         ll cont=0;
      |            ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 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 456 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 456 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 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 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 456 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 456 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 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 2 ms 920 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 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 456 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 456 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 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 2 ms 920 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 17 ms 5468 KB Output is correct
32 Correct 17 ms 5468 KB Output is correct
33 Correct 17 ms 5316 KB Output is correct
34 Correct 15 ms 5464 KB Output is correct
35 Correct 18 ms 5468 KB Output is correct
36 Correct 16 ms 5464 KB Output is correct
37 Correct 16 ms 5468 KB Output is correct
38 Correct 16 ms 5464 KB Output is correct
39 Correct 17 ms 5468 KB Output is correct
40 Correct 15 ms 5280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 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 456 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 456 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 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 2 ms 920 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 17 ms 5468 KB Output is correct
32 Correct 17 ms 5468 KB Output is correct
33 Correct 17 ms 5316 KB Output is correct
34 Correct 15 ms 5464 KB Output is correct
35 Correct 18 ms 5468 KB Output is correct
36 Correct 16 ms 5464 KB Output is correct
37 Correct 16 ms 5468 KB Output is correct
38 Correct 16 ms 5464 KB Output is correct
39 Correct 17 ms 5468 KB Output is correct
40 Correct 15 ms 5280 KB Output is correct
41 Correct 905 ms 196148 KB Output is correct
42 Correct 876 ms 196432 KB Output is correct
43 Correct 874 ms 196344 KB Output is correct
44 Correct 876 ms 196308 KB Output is correct
45 Correct 879 ms 196304 KB Output is correct
46 Correct 873 ms 196528 KB Output is correct
47 Correct 854 ms 196152 KB Output is correct
48 Correct 857 ms 196176 KB Output is correct
49 Correct 865 ms 196384 KB Output is correct
50 Correct 851 ms 196268 KB Output is correct
51 Correct 862 ms 196384 KB Output is correct
52 Correct 862 ms 196396 KB Output is correct
53 Correct 852 ms 196432 KB Output is correct
54 Correct 860 ms 196384 KB Output is correct
55 Correct 863 ms 196380 KB Output is correct