제출 #877998

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
8779982023-11-24 01:57:14khoquennguoiminhthuongSafety (NOI18_safety)C++14
40 / 100
301 ms197712 KiB
#include<bits/stdc++.h>
using namespace std;
int n;
int lim;
int a[200005];
namespace sub12567
{
long long dp[5005][5005];
void solve()
{
for(int i=1;i<=n;i++)
for(int j=1;j<=5000;j++)
dp[i][j]=1e18;
for(int i=0;i<=5000;i++)dp[1][i]=abs(a[1]-i);
for(int i=2;i<=n;i++)
{
deque<int>dq;
int dd=0;
for(int j=0;j<=5000;j++)
{
int l=max(0,j-lim),r=min(5000,j+lim);
while(dd<=r)
{
while(dq.size()&&dp[i-1][dq.back()]>=dp[i-1][dd])dq.pop_back();
dq.push_back(dd);
dd++;
}
while(dq.size()&&dq.front()<l)dq.pop_front();
if(dq.size())dp[i][j]=dp[i-1][dq.front()]+abs(a[i]-j);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...