QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#555710#5981. Costly Binary Searchzyxawa0 0ms0kbC++23657b2024-09-10 08:35:522024-09-10 08:35:53

Judging History

你现在查看的是最新测评结果

  • [2024-09-10 08:35:53]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-09-10 08:35:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int t,n,a[1000001],dp[10001][10001];
char s[1000001];
void solve(int t){
    scanf("%s",s+1),n=strlen(s+1);
    for(int i=1;i<=n;i++) a[i]=s[i]-48;
    memset(dp,0x3f,sizeof(dp));
    for(int i=1;i<=n;i++) dp[i][i]=a[i],dp[i][i-1]=dp[i+1][i]=0;
    for(int k=2;k<=n;k++){
        for(int l=1,r=k;r<=n;l++,r++){
            for(int i=l;i<=r;i++) dp[l][r]=min(dp[l][r],max(dp[l][i-1],dp[i+1][r])+a[i]);
        }
    }
    printf("Case #%d: %d\n",t,dp[1][n]);
}
int main(){
	scanf("%d",&t);
    for(int i=1;i<=t;i++) solve(i);
    return 0;
}
// dp[l][r]表示确定x在[l,r]中的最小代价

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

50
8
5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #2:

score: 0
Runtime Error

input:

50
647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...

output:


result: