# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
830698 |
2023-08-19T09:35:03 Z |
vjudge1 |
Safety (NOI18_safety) |
C++17 |
|
397 ms |
201992 KB |
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int nmax = 200002;
int S[nmax];
int dp[5005][5005];
int main() {
int N;
int H;
cin >> N >> H;
for(int i=1; i<=N; i++) {
cin >> S[i];
}
deque<pair<int,int>>dd;
for(int i=0; i<=5000; i++) dp[1][i] = abs(S[1]-i);
for(int i=2; i<=N; i++) {
dd.clear();
for(int j=0; j<=min(5000, H); j++) {
while(!dd.empty() && dd.back().fi > dp[i-1][j]) {
dd.pop_back();
}
dd.push_back({dp[i-1][j],j});
}
pair<int,int>sem;
for(int j=0; j<=5000; j++) {
if(!dd.empty() && dd.front().se < j-H) {
dd.pop_front();
}
sem = dd.front();
dp[i][j] = sem.fi + abs(S[i]-j);
if(j-H+1 <= 5000) {
while(!dd.empty() && dd.back().fi > dp[i-1][j+H+1]) {
dd.pop_back();
}
dd.push_back({dp[i-1][j+H+1], j+H+1});
}
}
}
int jwb = INT_MAX;
for(int i=0; i<=5000; i++) {
jwb = min(jwb, dp[N][i]);
}
cout << jwb << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
560 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
397 ms |
201992 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |