QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#333923#5656. Vittorio Plays with LEGO BricksMilanTL 1ms4000kbC++231.3kb2024-02-20 20:10:282024-02-20 20:10:29

Judging History

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

  • [2024-02-20 20:10:29]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:4000kb
  • [2024-02-20 20:10:28]
  • 提交

answer

#include <bits/stdc++.h>
#define MULTI int _; cin >> _; while(_--)
#define fi first
#define se second
#define pb(a) push_back(a)
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, n, m) for(int i = n; i <= m; i++)
#define repsv(i, n, m) for(int i = n; i >= m; i--)
#define vsz(a) (int)(a.size())
#define mp(a, b) make_pair(a, b)
#define all(a) a.begin(), a.end()

using namespace std;

typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;

#ifdef LOCAL
#include "debugs.hpp"
#else
#define dbg(...) 0
#endif

int dp[300][300];
int n, h;
vi b;

inline int save(int l, int r){
    return max(0, h+1-((b[r]-b[l])%2 ? (b[r]-b[l])/2 + 1 : (b[r]-b[l])/2));
}

int calc(int l, int r){
    if(l==r) return h;
    if(dp[l][r]!=-1)
        return dp[l][r];
    int res = INT_MAX;
    reps(m, l, r-1)
        res = min(res, calc(l, m) + calc(m+1, r) - save(l, r));
    return res;
}

void solve(){
    rep(i,300)rep(j,300)dp[i][j]=-1;
    cin >> n >> h;
    b = vi(n);
    rep(i, n)
        cin >> b[i];
    cout << calc(0, n-1) << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    // MULTI
    solve();
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 4000kb

input:

4 0
2 7 11 13

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3988kb

input:

4 1
2 7 11 13

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3908kb

input:

4 100
2 7 11 13

output:

107

result:

ok single line: '107'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3960kb

input:

4 3
2 5 8 11

output:

8

result:

ok single line: '8'

Test #5:

score: -100
Time Limit Exceeded

input:

294 6
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 44 46 48 50 52 54 56 58 60 62 64 66 68 70 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 157 159 161 163 165 167 169 171 173 175 177 ...

output:


result: