이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a), _b =(b); i <= _b; i++)
#define FORD(i, a, b) for(int i = (a), _b =(b); i >= _b; i--)
#define MASK(i) (1LL << (i))
#define BIT(x, i) ((x >> i) & 1)
#define popc(i) __builtin_popcountll(i)
#define fi first
#define se second
#define ALL(v) (v).begin(),(v).end()
#define pii pair<int, int>
using ll = long long;
using namespace std;
const int maxn = 2e3 + 10;
int n,m;
struct state{
int c,f,v;
bool operator < (const state &other) const{
return f > other.f;
}
};
vector<state> com;
vector<state> cus;
int maxcnt;
long long res(0);
namespace sub3{
const int maxn1 = 2e3 + 2;
long long dp[2][maxn1][101];
void solve(){
memset(dp,-0x3f,sizeof dp);
long long oo = dp[1][1][1];
dp[0][0][0] = 0;
FOR(i,0,n){
memset(dp[(i + 1) & 1],-0x3f,sizeof dp[(i + 1) & 1]);
FOR(j,0,m)
FOR(cnt,0,100)
if(dp[i & 1][j][cnt] > oo){
if(i < n)
dp[(i + 1) & 1][j][cnt] = max(dp[(i + 1) & 1][j][cnt],dp[i & 1][j][cnt]);
if(j < m)
dp[i & 1][j + 1][cnt] = max(dp[i & 1][j + 1][cnt],dp[i & 1][j][cnt]);
if(i < n && cnt + com[i + 1].c <= 100)
dp[(i + 1) & 1][j][cnt + com[i + 1].c] = max(dp[(i + 1) & 1][j][cnt + com[i + 1].c],dp[i & 1][j][cnt] - com[i + 1].v);
if(i >= 1 && cnt >= cus[j + 1].c && com[i].f >= cus[j + 1].f && j < m)
dp[i & 1][j + 1][cnt - cus[j + 1].c] = max(dp[i & 1][j + 1][cnt - cus[j + 1].c],dp[i & 1][j][cnt] + cus[j + 1].v);
}
}
FOR(cnt,0,100)
res = max(res,dp[n & 1][m][cnt]);
cout << res;
}
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "test"
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> n;
FOR(i,1,n){
int c,f,v;
cin >> c >> f >> v;
com.push_back({c,f,v});
}
int tmp = 1e9;
com.push_back({0,tmp + 1,-1});
sort(ALL(com));
cin >> m;
FOR(i,1,m){
int c,f,v;
cin >> c >> f >> v;
cus.push_back({c,f,v});
}
cus.push_back({0,tmp + 1,-1});
sort(ALL(cus));
sub3::solve();
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
clo.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |