Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
37416 | 李羽乔 | 【S】T3 | C++ | 运行超时 | 12 | 2000 MS | 376444 KB | 1350 | 2025-03-30 14:15:27 |
#include<bits/stdc++.h> using namespace std; const int N = 1e5+10; int n; long long a[N]; int dp[N][31][31]; int cal(int x){ if(x<0) return -x; else return x; } int main(){ //freopen("c3.in","r",stdin); //freopen("c.out","w",stdout); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=0;i<=n;i++){ for(int j=0;j<=30;j++){ for(int k=0;k<=30;k++){ dp[i][j][k]=1e9; } } } dp[0][0][0]=0; for(int i=1;i<=n;i++){ for(int j=0;j<=30;j++){ for(int q=0;q<=30;q++){ for(int k=0;k<=30;k++){ for(int p=0;p<=30;p++){ long long x=a[i-1],y=a[i]; x=(x>>j); x=(x<<q); y=(y>>k); y=(y<<p); if(y>=x){ dp[i][k][p]=min(dp[i-1][j][q]+k+p,dp[i][k][p]); } } } } } } int ans=1e9; for(int i=0;i<=30;i++){ for(int j=0;j<=30;j++){ ans=min(ans,dp[n][i][j]); } } cout<<ans<<endl; return 0; }