Submission #759228

# Submission time Handle Problem Language Result Execution time Memory
759228 2023-06-15T21:43:29 Z 1075508020060209tc Group Photo (JOI21_ho_t3) C++14
64 / 100
5000 ms 468 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int lowbit(int x){return x&-x;}
int bit[200005];

void upd(int pl,int val){
while(pl<=5000){
    bit[pl]+=val;
    pl+=lowbit(pl);
}
}
int qsum(int pl){
int ret=0;
while(pl){
    ret+=bit[pl];
    pl-=lowbit(pl);
}
return ret;
}



int n;
int ar[5010];
int dp[5010];


signed main(){
cin>>n;
for(int i=1;i<=n;i++){
    cin>>ar[i];
}

dp[0]=0;
for(int i=1;i<=n;i++){

    for(int j=0;j<=i-1;j++){
        int cal=dp[j];
        for(int a=1;a<=5000;a++){
            bit[a]=0;
        }

        for(int a=1;a<=n;a++){
            if(ar[a]>j&&ar[a]<=i){
                //for(int b=1;b<a;b++){
                  //  if((ar[b]<ar[a]&&ar[b]>j)||(ar[b]>i) ){cal++;}
                //}
                cal+=qsum(ar[a]);
            }
            if(ar[a]>j&&ar[a]<=i){
                upd(ar[a],1);
            }
            if(ar[a]>i){
                upd(1,1);
            }
        }
        if(j==0){dp[i]=cal;}
        dp[i]=min(dp[i],cal);
    }
   // cout<<dp[i]<<" ";
}
cout<<dp[n]<<endl;




}
/*
6 5
1 2 1 100000
1 3 1 1
2 6 1 1000
2 4 1 1
2 5 1 1
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 34 ms 304 KB Output is correct
22 Correct 35 ms 340 KB Output is correct
23 Correct 34 ms 340 KB Output is correct
24 Correct 35 ms 340 KB Output is correct
25 Correct 35 ms 340 KB Output is correct
26 Correct 35 ms 308 KB Output is correct
27 Correct 35 ms 340 KB Output is correct
28 Correct 35 ms 340 KB Output is correct
29 Correct 34 ms 340 KB Output is correct
30 Correct 35 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 34 ms 304 KB Output is correct
22 Correct 35 ms 340 KB Output is correct
23 Correct 34 ms 340 KB Output is correct
24 Correct 35 ms 340 KB Output is correct
25 Correct 35 ms 340 KB Output is correct
26 Correct 35 ms 308 KB Output is correct
27 Correct 35 ms 340 KB Output is correct
28 Correct 35 ms 340 KB Output is correct
29 Correct 34 ms 340 KB Output is correct
30 Correct 35 ms 456 KB Output is correct
31 Correct 1881 ms 340 KB Output is correct
32 Correct 1883 ms 344 KB Output is correct
33 Correct 1845 ms 344 KB Output is correct
34 Correct 1904 ms 464 KB Output is correct
35 Correct 1857 ms 468 KB Output is correct
36 Correct 1871 ms 344 KB Output is correct
37 Correct 1848 ms 348 KB Output is correct
38 Correct 1844 ms 340 KB Output is correct
39 Correct 1976 ms 356 KB Output is correct
40 Correct 1881 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 34 ms 304 KB Output is correct
22 Correct 35 ms 340 KB Output is correct
23 Correct 34 ms 340 KB Output is correct
24 Correct 35 ms 340 KB Output is correct
25 Correct 35 ms 340 KB Output is correct
26 Correct 35 ms 308 KB Output is correct
27 Correct 35 ms 340 KB Output is correct
28 Correct 35 ms 340 KB Output is correct
29 Correct 34 ms 340 KB Output is correct
30 Correct 35 ms 456 KB Output is correct
31 Correct 1881 ms 340 KB Output is correct
32 Correct 1883 ms 344 KB Output is correct
33 Correct 1845 ms 344 KB Output is correct
34 Correct 1904 ms 464 KB Output is correct
35 Correct 1857 ms 468 KB Output is correct
36 Correct 1871 ms 344 KB Output is correct
37 Correct 1848 ms 348 KB Output is correct
38 Correct 1844 ms 340 KB Output is correct
39 Correct 1976 ms 356 KB Output is correct
40 Correct 1881 ms 344 KB Output is correct
41 Execution timed out 5056 ms 384 KB Time limit exceeded
42 Halted 0 ms 0 KB -