제출 #1360644

#제출 시각아이디문제언어결과실행 시간메모리
1360644kaiCloud Computing (CEOI18_clo)C++20
72 / 100
409 ms2188 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define el '\n'
#define all(x) begin(x), end(x)
#define sz(s) (int)(s.size())

inline void setIO(string s) {
    if(fopen((s + ".in").c_str(), "r")){
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
}

const int MOD = 1e9+7; //998244353;
const int N = 1e5 + 36;
const int NEG = -1e16;
int dp[N], ndp[N];
int n, m;

void Solve(){
    memset(dp, -0x3f, sizeof dp);
    vector<array<int, 3>> vt;
    int c, f, v;
    int sum_c = 0;
    cin>> n;
    for(int i=0; i<n; i++){
        cin>> c>> f>> v;
        vt.push_back({c, f, -v});
        sum_c += c;
    }

    cin>> m;
    for(int i=0; i<m; i++){
        cin>> c>> f>> v;
        vt.push_back({-c, f, v});
    }
    
    sort(all(vt), [](array<int, 3> a, array<int, 3> b){
        return a[1] > b[1];
    });

    dp[0] = 0;
    for(auto [cores, f, v]: vt){
        for(int i=0; i<=sum_c; i++) ndp[i] = dp[i];

        for(int c=0; c<=sum_c; c++){
            if(dp[c] <= NEG) continue;

            int nc = c + cores;

            if(nc >= 0 && nc <= sum_c){
                ndp[nc] = max(ndp[nc], dp[c] + v);
            }
        }

        swap(dp, ndp);
    }

    int ans = 0;
    for(int c=0; c<=sum_c; c++) ans = max(ans, dp[c]);

    cout<< ans<<el;

}

signed main (){
    setIO("Rem");
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int T(1);
    // cin >> T;
    while(T--) Solve();

    return 0;
}

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

clo.cpp: In function 'void setIO(std::string)':
clo.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen((s + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…