Submission #56097

#TimeUsernameProblemLanguageResultExecution timeMemory
56097BenqMountains (IOI17_mountains)C++14
100 / 100
60 ms15332 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define F0R(i, a) for (int i=0; i<(a); i++) #define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() const int MOD = 1000000007; const ll INF = 1e18; const int MX = 100001; int dp[2000][2000], pos[2000]; bool above(pi a, pi b, pi c) { b.f -= a.f, b.s -= a.s; c.f -= a.f, c.s -= a.s; return (ll)c.s*b.f-(ll)c.f*b.s >= 0; } int get(int l, int r) { if (l > r) return 0; return dp[l][r]; } void ad(int x, int y) { pos[x] = y; dp[x][x] = 1; int sum = 1, bes = x; vi cur = {x}; F0Rd(i,x) { dp[i][x] = dp[i][x-1]; if (above({i,pos[i]},{bes,pos[bes]},{x,pos[x]})) { bes = i; sum += get(i+1,cur.back()-1); cur.pb(i); } dp[i][x] = max(dp[i][x],sum+get(i,cur.back()-1)); } } int maximum_deevs(vi v) { F0R(i,sz(v)) ad(i,v[i]); return dp[0][sz(v)-1]; } /*int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << maximum_deevs({1,2,3,4,5,6}); }*/ /* Look for: * the exact constraints (multiple sets are too slow for n=10^6 :( ) * special cases (n=1?) * overflow (ll vs int?) * array bounds */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...