이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
const int N = 1e6+50, inf = 1e17;
//int mod = 998244353
//int mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng)
struct line{
int m, c;
line(int _m,int _c) : m(_m), c(_c){
};
int calc(int x){
return m * x + c;
};
double xnt(line & other){
return (double)(c - other.c)/(m - other.m);
};
};
void solve(){
int s, n;
cin >> s >> n;
vector<array<int,3>> v(n);
for(auto &i:v)
cin >> i[0] >> i[1] >> i[2];
map<int,vector<array<int,2>> > mp;
for(auto i:v)mp[i[1]].pb({i[0], i[2]});
for(auto &[id, ve]:mp)sort(rall(ve));
vector<int> dp(s+5, 0);
for(auto [we, ve]:mp){//2000
int mx = s/we;
int id = 0;
int cnt = 0;
int sz = ve.size();//loglog(2000)
while(id < sz && cnt < mx){
for(int i = s; i >= we; i--){//2000
chmax(dp[i], dp[i-we] + ve[id][0]);
}
ve[id][1]--;
if(ve[id][1] == 0)id++;
cnt++;
}
}
cout << *max_element(all(dp)) << '\n';
//4000loglog(2000);
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'void solve()':
knapsack.cpp:59:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
59 | for(auto &[id, ve]:mp)sort(rall(ve));
| ^
knapsack.cpp:62:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
62 | for(auto [we, ve]:mp){//2000
| ^
# | 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... |