Submission #940845

# Submission time Handle Problem Language Result Execution time Memory
940845 2024-03-07T18:34:30 Z Maite_Morale Group Photo (JOI21_ho_t3) C++14
100 / 100
633 ms 149588 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define MAX 5005
#define oo 1e18
#define mod 1000000007
#define fast_in ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(0);
using namespace std;
typedef long long ll;
#define pll pair<ll , ll>
#define vll vector<ll>
#define vvll vector<vll>
#define vpll vector<pll>
 
struct ABI{
    vll sum;
    ABI(ll n){
        sum.assign(n+10,0);
    }
    void update(ll a,ll b){
        if(a<1 || a>=sum.size()){cout<<"anormalona";return;}
        for(a;a<sum.size();a+=(a&-a))sum[a]+=b;
    }
    ll query(ll a){ll r=0;
        if(a<1)return r;
        a=min(a,(ll)sum.size()-1);
        for(a;a>0;a-=(a&-a))r+=sum[a];
    return r;
    }
    ll query(ll a,ll b){
        if(a>b)swap(a,b);
        return query(b)-query(a-1);
    }
} abi1(MAX),abi2(MAX);
ll t,n,a[MAX],mp[MAX],best[MAX],dp[MAX][MAX];
int main(){
    fast_in
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];mp[a[i]]=i;
        best[i]=oo;
    }
    for(int i=1;i<=n;i++){
        dp[i][i-1]=best[i-1];
        for(int j=i;j<=n;j++){
            dp[i][j]=dp[i][j-1]+j-1-abi1.query(1,mp[j])-abi2.query(mp[j],n+1);

            abi2.update(mp[j],1);
        }
        for(int j=i;j<=n;j++){
            best[j]=min(best[j],dp[i][j]);
            abi2.update(mp[j],-1);
        }
        abi1.update(mp[i],1);
    }
    cout<<best[n];
return 0;
}

Compilation message

Main.cpp: In member function 'void ABI::update(ll, ll)':
Main.cpp:21:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         if(a<1 || a>=sum.size()){cout<<"anormalona";return;}
      |                   ~^~~~~~~~~~~~
Main.cpp:22:13: warning: statement has no effect [-Wunused-value]
   22 |         for(a;a<sum.size();a+=(a&-a))sum[a]+=b;
      |             ^
Main.cpp:22:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for(a;a<sum.size();a+=(a&-a))sum[a]+=b;
      |               ~^~~~~~~~~~~
Main.cpp: In member function 'll ABI::query(ll)':
Main.cpp:27:13: warning: statement has no effect [-Wunused-value]
   27 |         for(a;a>0;a-=(a&-a))r+=sum[a];
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 8536 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 3 ms 8540 KB Output is correct
24 Correct 3 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 8536 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 3 ms 8540 KB Output is correct
24 Correct 3 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 2 ms 8540 KB Output is correct
31 Correct 19 ms 33368 KB Output is correct
32 Correct 12 ms 33308 KB Output is correct
33 Correct 14 ms 33368 KB Output is correct
34 Correct 13 ms 33416 KB Output is correct
35 Correct 15 ms 33628 KB Output is correct
36 Correct 13 ms 33372 KB Output is correct
37 Correct 13 ms 33372 KB Output is correct
38 Correct 13 ms 33372 KB Output is correct
39 Correct 15 ms 33372 KB Output is correct
40 Correct 15 ms 33372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 8536 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 3 ms 8540 KB Output is correct
24 Correct 3 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 2 ms 8540 KB Output is correct
31 Correct 19 ms 33368 KB Output is correct
32 Correct 12 ms 33308 KB Output is correct
33 Correct 14 ms 33368 KB Output is correct
34 Correct 13 ms 33416 KB Output is correct
35 Correct 15 ms 33628 KB Output is correct
36 Correct 13 ms 33372 KB Output is correct
37 Correct 13 ms 33372 KB Output is correct
38 Correct 13 ms 33372 KB Output is correct
39 Correct 15 ms 33372 KB Output is correct
40 Correct 15 ms 33372 KB Output is correct
41 Correct 633 ms 149336 KB Output is correct
42 Correct 630 ms 149328 KB Output is correct
43 Correct 611 ms 149332 KB Output is correct
44 Correct 627 ms 149588 KB Output is correct
45 Correct 608 ms 148176 KB Output is correct
46 Correct 606 ms 148172 KB Output is correct
47 Correct 605 ms 146872 KB Output is correct
48 Correct 606 ms 148048 KB Output is correct
49 Correct 611 ms 148304 KB Output is correct
50 Correct 628 ms 149240 KB Output is correct
51 Correct 609 ms 149332 KB Output is correct
52 Correct 613 ms 149336 KB Output is correct
53 Correct 614 ms 148280 KB Output is correct
54 Correct 610 ms 148600 KB Output is correct
55 Correct 607 ms 148408 KB Output is correct