제출 #1169280

#제출 시각아이디문제언어결과실행 시간메모리
1169280mateuszwesJelly Flavours (IOI20_jelly)C++20
54 / 100
515 ms197052 KiB
#include "jelly.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned ll #define pb push_back #define pii pair<int,int> #define pl pair<ll,ll> #define F first #define S second #define pq priority_queue #define all(x) x.begin(), x.end() #define deb(x) cout << #x << " = " << x << '\n'; #define deb2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << '\n'; //cena moze byc rowna 0 vector<int> a; int dp1[10007][2007]; bool chek(int x, int y, int v){ int mtak = 0; for(int i = 0; i <= v; i++){ dp1[0][i] = 1; for(int j = 1; j <= x; j++){ dp1[j][i] = 0; if(i > 0){ dp1[j][i] = dp1[j][i-1]; if(j >= a[i-1]){ if(dp1[j-a[i-1]][i-1] == 1){ dp1[j][i] = 1; } } } if(dp1[j][i]) mtak = max(mtak, j); } } int sum = 0; for(int i = 0; i < v; i++) sum += a[i]; return y >= sum-mtak; } int find_maximum_unique(int x, int y, vector<int> a1, vector<int> b){ a = a1; int n = a.size(); bool p5 = 1; for(int i = 0; i < n; i++){ if(a[i] != b[i]){ p5 = 0; //deb(i); } } if(x <= 500 && y <= 500 && n <= 200){ int dp[x+7][y+7][n+7]; for(int x1 = 0; x1 <= x; x1++){ for(int y1 = 0; y1 <= y; y1++){ dp[x1][y1][0] = 0; } } for(int x1 = 0; x1 <= x; x1++){ for(int y1 = 0; y1 <= y; y1++){ for(int i = 1; i <= n; i++){ dp[x1][y1][i] = dp[x1][y1][i-1]; if(x1 >= a[i-1]) dp[x1][y1][i] = max(dp[x1][y1][i], dp[x1-a[i-1]][y1][i-1]+1); if(y1 >= b[i-1]) dp[x1][y1][i] = max(dp[x1][y1][i], dp[x1][y1-b[i-1]][i-1]+1); } } } return dp[x][y][n]; } else if(y == 0){ int sc = 0; for(int i = 0; i < n; i++) if(b[i] == 0) a[i] = 0; sort(all(a)); int ind = 0; for(int i = 0; i < n; i++){ if(a[i] <= x){ x -= a[i]; sc++; } } return sc; } else if(p5){ sort(all(a)); int bes = 0; int l = 0, r = n; while(r-l > 1){ //deb2(r,l); int mid = (l+r)/2; if(chek(x,y,mid)) l = mid; else r = mid-1; } if(chek(x,y,r)) bes = r; else bes = l; int sum = 0; for(int i = 0; i < bes; i++) sum += a[i]; return sum; } else{ int sc = 0; sort(all(a)); for(int i = 0; i < n; i++){ if(a[i] <= x){ x -= a[i]; sc++; } else if(b[i] <= y){ y -= b[i]; sc++; } } return sc; } return 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...