제출 #897527

#제출 시각아이디문제언어결과실행 시간메모리
897527phattruongPO344Cloud Computing (CEOI18_clo)C++17
54 / 100
1356 ms3924 KiB
#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]);
            dp[i & 1][0][0] = 0;
            dp[(i  + 1) & 1][0][0]  =0;
            FOR(j,0,m - 1)
                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]);
                        dp[i & 1][j + 1][cnt] = max(dp[i & 1][j + 1][cnt],dp[i & 1][j][cnt]);
                        if(i < n && cnt < 50)
                            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)
                            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 "cloud"
    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({-1,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({-1,tmp + 1,-1});
    sort(ALL(cus));
    sub3::solve();
}

컴파일 시 표준 에러 (stderr) 메시지

clo.cpp: In function 'int main()':
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".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
clo.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...