제출 #1247775

#제출 시각아이디문제언어결과실행 시간메모리
1247775fadyy287Knapsack (NOI18_knapsack)C++20
100 / 100
49 ms2952 KiB
#include<bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define endl "\n"
#define map unordered_map
typedef long long ll;
typedef long double ld;

void test(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
}


int main(){
    //test();
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll s,n;
    cin>>s>>n;
    vector<pair<ll,ll>> weight[s+1];
    for(ll i=0;i<n;++i){
        ll v,w,k;
        cin>>v>>w>>k;
        if(w<=s && k) weight[w].push_back({v,k});
    }

    ll dp[s+1]{};
    for(ll i=1;i<=s;++i){
        sort(weight[i].rbegin(),weight[i].rend());
        ll dd[s+1]{};
        for(ll j=1;j<=s;++j){
            ll num=0;
            ll got=0;
            ll ww=0;
            ll value=0;
            ll pos=0;
            while(ww<=j-i){
                if(pos==weight[i].size()) break;
                if(got==weight[i][pos].second){
                    got=0;
                    pos++;
                    continue;
                }
                value+=weight[i][pos].first;
                ww+=i;
                got++;
                dd[j]=max(dd[j],dp[j-ww]+value);
                //cout<<i<<" "<<j<<" "<<dd[j]<<" "<<got<<" "<<pos<<endl;
            }
        }
        for(ll j=1;j<=s;++j){
            dp[j]=max(dd[j],dp[j]);
        }
    }

    cout<<dp[s];

}

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

knapsack.cpp: In function 'void test()':
knapsack.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:11:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     freopen("out.txt", "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...