Submission #75708360


Source Code Expand

#include<bits/stdc++.h>
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,l,r) for(int i=(r);i>=(l);--i)

using namespace std;
const int N=35,M=1500;
int T,n,a[N],len[N],s[N][1700],f[1700][1700],dp[1700],ndp[1700];

void solve(){
    cin>>n;rep(i,1,n){
        cin>>a[i];len[i]=0;int x=a[i];
        while(x)s[i][++len[i]]=x&1,x>>=1;
        rep(j,len[i]+1,1510)s[i][j]=0;
    }
    rep(k,0,M)dp[k]=len[1]+k;
    rep(i,2,n){
        rep(u,1,len[i-1]+M)rep(v,1,len[i]+M)f[u][v]=s[i-1][u]==s[i][v]?f[u-1][v-1]+1:max(f[u-1][v],f[u][v-1]);
        rep(k,0,M){ndp[k]=INF;rep(kp,0,M)ndp[k]=min(ndp[k],dp[kp]+len[i]+k-f[len[i-1]+kp][len[i]+k]);}
        rep(k,0,M)dp[k]=ndp[k];
    }
    int ans=INF;rep(k,0,M)ans=min(ans,dp[k]);cout<<ans<<"\n";
    return;
}

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>T;while(T--)solve();
    return 0;
}

Submission Info

Submission Time
Task F - Range Division
User Fourier_WJY
Language C++23 (GCC 15.2.0)
Score 600
Code Size 958 Byte
Status AC
Exec Time 123 ms
Memory 24852 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 1
AC × 34
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 39 ms 23696 KiB
01_handmade_00.txt AC 1 ms 3664 KiB
01_handmade_01.txt AC 1 ms 3708 KiB
01_handmade_02.txt AC 43 ms 24400 KiB
01_handmade_03.txt AC 40 ms 23660 KiB
01_handmade_04.txt AC 37 ms 23604 KiB
01_handmade_05.txt AC 62 ms 23628 KiB
01_handmade_06.txt AC 70 ms 24428 KiB
01_handmade_07.txt AC 39 ms 24084 KiB
01_handmade_08.txt AC 122 ms 24772 KiB
01_handmade_09.txt AC 115 ms 24672 KiB
01_handmade_10.txt AC 112 ms 24372 KiB
01_handmade_11.txt AC 98 ms 24552 KiB
02_random_00.txt AC 115 ms 24784 KiB
02_random_01.txt AC 117 ms 24780 KiB
02_random_02.txt AC 116 ms 24852 KiB
02_random_03.txt AC 117 ms 24720 KiB
02_random_04.txt AC 118 ms 24720 KiB
02_random_05.txt AC 115 ms 24720 KiB
02_random_06.txt AC 116 ms 24784 KiB
02_random_07.txt AC 117 ms 24824 KiB
02_random_08.txt AC 109 ms 24444 KiB
02_random_09.txt AC 123 ms 24812 KiB
02_random_10.txt AC 117 ms 24516 KiB
02_random_11.txt AC 110 ms 24516 KiB
02_random_12.txt AC 116 ms 24756 KiB
02_random_13.txt AC 117 ms 24784 KiB
02_random_14.txt AC 114 ms 24644 KiB
02_random_15.txt AC 82 ms 24388 KiB
02_random_16.txt AC 94 ms 24388 KiB
02_random_17.txt AC 114 ms 24664 KiB
02_random_18.txt AC 119 ms 24672 KiB
02_random_19.txt AC 117 ms 24712 KiB
02_random_20.txt AC 115 ms 24804 KiB