QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#699746#5981. Costly Binary SearchXuYueming0 0ms0kbC++23879b2024-11-02 10:34:212024-11-02 10:34:22

Judging History

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

  • [2024-11-02 10:34:22]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-11-02 10:34:21]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

// #define Hydro

const int N = 2010;

char cost[N];
int n;
int f[N][N];

int dfs(int l, int r) {
    if (l > r) return 0;
    if (f[l][r]) return f[l][r];
    int& res = f[l][r] = 0x3f3f3f3f;
    for (int i = l; i <= r; ++i)
        res = min(res, max(dfs(l, i - 1), dfs(i + 1, r)) + (cost[i] ^ 48));
    return res;
}

void solve() {
    scanf("%s", cost + 1);
    n = strlen(cost + 1);
    for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; ++j)
        f[i][j] = 0;
    printf("%d", dfs(1, n));
}

signed main() {
    #ifdef Hydro
    freopen("cost.in", "r", stdin);
    freopen("cost.out", "w", stdout);
    solve();
    #endif
    int t; scanf("%d", &t);
    for (int i = 1; i <= t; ++i)
        printf("Case #%d: ", i), solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

50
8
5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #2:

score: 0
Runtime Error

input:

50
647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...

output:


result: