제출 #928570

#제출 시각아이디문제언어결과실행 시간메모리
928570panJelly Flavours (IOI20_jelly)C++17
100 / 100
291 ms305232 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#include "bits_stdc++.h" #define f first #define s second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define input(x) scanf("%lld", &x); #define input2(x, y) scanf("%lld%lld", &x, &y); #define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z); #define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a); #define print(x, y) printf("%lld%c", x, y); #define show(x) cerr << #x << " is " << x << endl; #define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl; #define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); #define auto set<pi>:: iterator using namespace std; //using namespace __gnu_pbds; #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> #define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> typedef long long ll; typedef long double ld; typedef pair<ld, ll> pd; typedef pair<string, ll> psl; typedef pair<ll, ll> pi; typedef pair<ll, pi> pii; ll const INF = 1e13; int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) { ll n = a.size(); vector<pi> jelly(n+1); for (ll i=1; i<=n; ++i) jelly[i] = mp(a[i-1], b[i-1]); sort(jelly.begin(), jelly.end()); vector<vector<ll> > dp1(n+1, vector<ll> (x+1, INF)); dp1[0].assign(x+1, 0); for (ll i=1; i<=n; ++i) { ll A = jelly[i].f, B = jelly[i].s; for (ll j=0; j<=x; ++j) { dp1[i][j] = dp1[i-1][j]+B; if (j) dp1[i][j] = min(dp1[i][j-1], dp1[i][j]); if (j-A>=0) dp1[i][j] = min(dp1[i][j], dp1[i-1][j-A]); } } vector<vector<ll> > dp2(n+2, vector<ll> (y+1, INF)); dp2[n+1].assign(y+1, 0); for (ll i=n; i>=1; --i) { ll B = jelly[i].s; for (ll j=0; j<=y; ++j) { dp2[i][j] = dp2[i+1][j]; if (j) dp2[i][j] = max(dp2[i][j-1], dp2[i][j]); if (j>=B) dp2[i][j] = max(dp2[i][j], dp2[i+1][j-B] + 1); } } ll ans = 0; for (ll i=0; i<=n; ++i) { vector<ll>& now = dp1[i]; if (now[x]>y) continue; ans = max(ans, i + dp2[i+1][y-now[x]]); } return ans; }
#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...