| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1355116 | Aviansh | Developer (BOI25_dev) | C++20 | 1933 ms | 30960 KiB |
#include <bits/stdc++.h>
using namespace std;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int arr[n];
for(int &i : arr){
cin >> i;
}
vector<int>mem[n];
auto fin = [&] (int i){
mem[i].reserve(27);
for(int j = i-4;j<=i+4;j++){
if(j>=0&&j<n){
mem[i].push_back(arr[j]);
mem[i].push_back(arr[j]+1);
mem[i].push_back(arr[j]-1);
}
}
sort(mem[i].begin(),mem[i].end());
mem[i].erase(unique(mem[i].begin(),mem[i].end()),mem[i].end());
};
unordered_map<int,array<long long,2>> dp[2];
fin(0);
for(int i : mem[0]){
dp[0][i][0]=dp[0][i][1]=abs(i-arr[0]);
}
for(int i = 1;i<n;i++){
dp[i%2].clear();
fin(i);
for(int h : mem[i]){
dp[i%2][h][0]=1e18;
dp[i%2][h][1]=1e18;;
for(int H : mem[(i-1)]){
if(H<h){
dp[i%2][h][1]=min(dp[i%2][h][1],dp[(i-1)%2][H][0]);
}
else if(H>h){
dp[i%2][h][0]=min(dp[i%2][h][0],dp[(i-1)%2][H][1]);
}
else{
dp[i%2][h][0]=min(dp[i%2][h][0],dp[(i-1)%2][H][0]);
dp[i%2][h][1]=min(dp[i%2][h][1],dp[(i-1)%2][H][1]);
}
}
dp[i%2][h][0]+=abs(arr[i]-h);
dp[i%2][h][1]+=abs(arr[i]-h);
}
}
long long ans = 1e18;
for(int i : mem[n-1]){
ans=min({dp[(n-1)%2][i][0],dp[(n-1)%2][i][1],ans});
}
cout << ans;
return 0;
}
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
