이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const int MOD = 1e9 + 7;
const int MAXN = 1e6+1;
struct specs{
int core, speed, value;
inline bool operator<(specs b) const{
return speed > b.speed;
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<specs> comp(n);
bool c1 = 1, s1 = 1, v1 = 1;
int corecount = 0;
for(int i = 0; i < n; i++)
cin >> comp[i].core >> comp[i].speed >> comp[i].value, corecount+=comp[i].core,c1 = c1&&(comp[i].core==1), s1 = s1&&(comp[i].speed==1),v1 = v1&&(comp[i].value==1);
int m;
cin >> m;
vector<specs> order(m);
for(int i = 0; i < m; i++)
cin >> order[i].core >> order[i].speed >> order[i].value, c1 = c1&&(order[i].core==1), s1 = s1&&(order[i].speed==1),v1 = v1&&(order[i].value==1);
sort(comp.begin(),comp.end());
sort(order.begin(),order.end());
if(n<=15){
int resp = 0;
for(int mask = 0; mask < (1<<n); mask++){
vector<int>dp(corecount+1,0);
int gasto = 0;
for(int i = 0; i < n; i++)
if(mask&(1<<i))
gasto+=comp[i].value;
int ptr = 0;
int available = 0;
for(int i = 0; i < m; i++){
while(ptr < n && comp[ptr].speed>=order[i].speed){
if(mask&(1<<ptr))
available+=comp[ptr].core;
ptr++;
}
for(int j = available; j >= 0; j--){
if(j-order[i].core>=0){
dp[j] = max(dp[j],dp[j-order[i].core] + order[i].value);
}
}
}
resp = max(resp,dp[available]-gasto);
}
cout << resp << '\n';
} else if(m <= 15){
} else if(c1){
} else if(s1){
} else if(v1){
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |