QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#265835 | #5656. Vittorio Plays with LEGO Bricks | BitsPlease# | WA | 0ms | 3856kb | C++20 | 1.3kb | 2023-11-25 21:33:31 | 2023-11-25 21:33:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (int)1e9+5;
void solve(){
int n, h;
cin >> n >> h;
vector<ll> a(n);
for(ll& x: a)cin >> x;
if (!h)
return void(cout << 0);
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]; // 3 - 14 = 12/2 = 6 [2 3] [7 8]
if (i == j)
dis = 2;
ll bricks = (dis+1)/2;
if (bricks > h)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) <= 1)
alone = false;
else total++;
}
}
// if (i == n-1)
// cout << dp[j] << ' ' << dp[i+1] << ' ' << total << ' ' << bricks << endl;
dp[i+1] = min(dp[i+1], dp[j] + total);
}
}
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: 0ms
memory: 3620kb
input:
4 0 2 7 11 13
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
4 1 2 7 11 13
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
4 100 2 7 11 13
output:
107
result:
ok single line: '107'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
4 3 2 5 8 11
output:
8
result:
ok single line: '8'
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3524kb
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'