QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#699729 | #5981. Costly Binary Search | XuYueming | 0 | 0ms | 3920kb | C++23 | 659b | 2024-11-02 10:31:59 | 2024-11-02 10:32:01 |
answer
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
// #define Hydro
const int N = 2010;
char cost[N];
int n;
int dfs(int l, int r) {
static int f[N][N];
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;
}
signed main() {
#ifdef Hydro
freopen("cost.in", "r", stdin);
freopen("cost.out", "w", stdout);
#endif
scanf("%s", cost + 1);
n = strlen(cost + 1);
printf("%d", dfs(1, n));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3852kb
input:
50 8 5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...
output:
5
result:
wrong answer 1st lines differ - expected: 'Case #1: 8', found: '5'
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 3920kb
input:
50 647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...
output:
5
result:
wrong answer 1st lines differ - expected: 'Case #1: 42', found: '5'