Submission #621247

#TimeUsernameProblemLanguageResultExecution timeMemory
621247PoonYaPatLightning Rod (NOI18_lightningrod)C++14
11 / 100
1541 ms262144 KiB
#include <bits/stdc++.h> using namespace std; const int MX=10000005; int n,a[MX],b[MX],pre[MX],pos[MX],dp[MX]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for (int i=1; i<=n; ++i) { int x,y; cin>>x>>y; a[i]=x-y; b[i]=x+y; } for (int i=1; i<=n; ++i) { int idx=i-1; while (a[i]<=a[idx] && idx>=1) idx=pre[idx]; pre[i]=idx; } for (int i=n; i>=1; --i) { int idx=i+1; while (b[i]>=b[idx] && idx<=n) idx=pos[idx]; pos[i]=idx; } memset(dp,0x3f,sizeof(dp)); dp[0]=0; for (int i=1; i<=n; ++i) dp[pos[i]-1]=min(dp[pos[i]-1],dp[pre[i]]+1); cout<<dp[n]; }
#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...