Submission #673798

#TimeUsernameProblemLanguageResultExecution timeMemory
673798sudheerays123Lightning Rod (NOI18_lightningrod)C++17
66 / 100
1339 ms262144 KiB
#include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ll long long int const ll N = 100+5 , INF = 1e18 , MOD = 1e9+7; bool inside(ll x1 , ll y1 , ll x2 , ll y2){ return (abs(x2-x1) <= (y2-y1)); } void solve(){ ll n; cin >> n; vector<pair<ll,ll>> a(n+5); for(ll i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; vector<ll> leftadd(n+5) , leftinclude(n+5,INF); for(ll i = 1; i <= n; i++){ ll last = INF; for(ll j = i-1; j >= 1; j--){ if(!(inside(a[j].first,a[j].second,a[i].first,a[i].second))){ last = j+1; break; } } if(last == INF) last = 1; leftadd[i] = last; } for(ll i = 1; i <= n; i++){ for(ll j = i+1; j <= n; j++){ if((inside(a[j].first,a[j].second,a[i].first,a[i].second))){ leftinclude[j] = min(leftinclude[j],i); } else break; } } vector<ll> dp(n+5); dp[1] = 1; for(ll i = 1; i <= n; i++){ dp[i] = dp[leftadd[i]-1]+1; if(leftinclude[i] != INF) dp[i] = min(dp[i],dp[leftinclude[i]]); } cout << dp[n]; } int main(){ fast; ll tc = 1; // cin >> tc; while(tc--) solve(); return 0; }
#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...