QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#265859 | #5656. Vittorio Plays with LEGO Bricks | BitsPlease# | WA | 1ms | 3480kb | C++20 | 1.2kb | 2023-11-25 21:53:52 | 2023-11-25 21:53:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = (ll)3e13 + 5;
void solve(){
int n, h;
cin >> n >> h;
vector<ll> a(n);
for(ll& x: a)cin >> x;
vector<ll> dp(n + 1, INF);
dp[0] = 0;
for(int i = 0; i < n; i++){
for(int j = i; j >= 0; j--){
ll dis = a[i] - a[j];
if (i == j)
dis = 2;
ll bricks = (dis + 1) / 2;
if (bricks > h)continue;
if (bricks > 1e6)continue;
ll total = bricks * (bricks - 1) / 2 + (h - bricks) + 1 - max((2 * (bricks - 3) - 1), 0LL);
bool alone = true;
for(int k = j + 1; k <= i; k++){
if (!alone){
alone = true;
total++;
} else {
if (a[k] - (a[k - 1] + 1) < 2)
alone = false;
else total++;
}
}
dp[i + 1] = min(dp[i + 1], dp[j] + total);
}
}
if (dp[n] == INF)cout << 0;
else cout << dp[n];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(6);
int t = 1;
// cin >> t;
while(t--){
solve();
cout << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3412kb
input:
4 0 2 7 11 13
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
4 1 2 7 11 13
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3364kb
input:
4 100 2 7 11 13
output:
107
result:
ok single line: '107'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3368kb
input:
4 3 2 5 8 11
output:
8
result:
ok single line: '8'
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3480kb
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:
548
result:
wrong answer 1st lines differ - expected: '588', found: '548'