이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
.;;;;:
:::::::;
;::::::;
:;;;;.
;:::;
;:::::;; ;;;
::::::::::;; ;:::
;:::::::::::;;: .;;:::
.;::::::::::::::;;. .:.:::: ;;;:::;;;
:;:::::::::::::::::;;. :. .::::....: :;;::::::::;
;::::::::::....:::::::;;;;;;;;;;: .:... ....:..: .;;::::::::::::;
:;::::::::........::::::::::::::. :. .. ... . .....;;;:::::::::::::::;
;::::::::..........::::::::::::: .... ..... .....:::::::::::::::::;:
.;:::::::...........:::::::::::: :.. ... ...........:::::::::::::::;.
......................::::::::::: .. .... ..............:::::::::::;
..........:::.......:::::::::::::. . .. .... ............:::::::::;
..........::::::::::::::::.......: .:.... ... ........ .: ::::::;;
........:::::::::::::...........:. ::. .... .... .... .: .::::;:
.......:::::::::::::..............::. .::.. .. .... .:..:::;:
...::::::::::::::::..:::....::....::::. :.... .... .... : ::.
;::::::::::::::::::..::.....:::...::::::::. .:. ... ..... .. .
:;::::::::;; .;:::::............::::::::::: :.... ... .. :.:
;:::::::;. ;;:::.......:::::;;;;..;;;::. :.... .... ...:
;:::::;: .;;::::::;;;;. ;;:... .. .. .:. .
;:::::: :;;: .;:: ....... .:. :
;::::; ;. ;;:: :::.. .:;:
;;::;: :;;;;;; .;::::::::::::;
;::;: .;;;;;;; :;::::::::::::
.;:;: .::;;;;; .;::::::::::;.
.;;;.....;;;;;; ... .;:::::::::;.
;;:.... .:. ;;;;;; :;::::::::;.
:;:......... ..... ;:::::::;:
............. .. ...... :;:::::;:
................... .;;;. .:;. ;;:::;;:
.. ....... ..:;;:;; ;: :;::;;:
;.:::.. ..........:;;;;; .;...:.;;;;;. .
:;:;.................;.;:; ;::::::::: ;;;:::
.;....:........;; ;;:::; .:::::;;:::;.:::. .;:::::::
.:...:; ;..:.:.:::.:;;;:::. :;:: : ..:.:. .;:::::
::.........;;+:....:; .:..:: .::..; ;::;:;;:
;:...........::;;;;;: .:: .; ::..:. :. ;:::;. :.
::::::...;. :::: ..;;;. ;. ;;:::;.
.. ::.;:.;: .::;;; ;;;:::;;.
::.; :;;;;:::........; ;:::;:
.;...::::........;:.....:; ;:
*/
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define rep(i,a,b) for(int i=a; i<=b; ++i)
#define rev(i,b,a) for(int i=b; i>=a; --i)
#define pii pair<ll,ll>
using namespace std;
const int maxN = 1e6 + 7;
const ll inf = 1e9 + 7;
const ll moreinf = 1e16 + 7;
struct data{
ll V,W,K;
}a[maxN];
int n,s;
ll f[5002][2002];
vector<pii> item[2002];
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> s >> n;
rep(i,1,n) cin >> a[i].V >> a[i].W >> a[i].K;
rep(i,1,n){
item[a[i].W].emplace_back(a[i].V, a[i].K);
}
rep(i,1,s){
sort(begin(item[i]),end(item[i]), [](pii a, pii b)->bool{
return a.first > b.first;
});
}
// rep(i,1,s){
// if(item[i].empty()) continue;
// for(auto it:item[i]) cout << it.first << " " << it.second << endl;
// // cout << endl;
// }
vector<pii> use_item;
rep(weight,1,s){
int cnt = 0;
for(auto it:item[weight]){
rep(i,1,it.second){
++cnt;
use_item.emplace_back(it.first,weight);
if(cnt>=s/weight) break;
}
if(cnt>=s/weight) break;
}
}
rep(i,0,use_item.size()-1){
rep(j,0,s){
f[i][j] = f[i-1][j];
if(j>=use_item[i].second) f[i][j] = max(f[i][j], f[i-1][j-use_item[i].second] + use_item[i].first);
}
}
cout << f[(int)use_item.size()-1][s];
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'int main()':
knapsack.cpp:53:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | #define rep(i,a,b) for(int i=a; i<=b; ++i)
......
99 | rep(i,0,use_item.size()-1){
| ~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:99:5: note: in expansion of macro 'rep'
99 | rep(i,0,use_item.size()-1){
| ^~~
# | 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... |