제출 #1096642

#제출 시각아이디문제언어결과실행 시간메모리
1096642dchang0524Knapsack (NOI18_knapsack)Java
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int S, N; cin >> S >> N; vector<ll> dp(S+1); unordered_map<int ,multiset<ll>> items; //<weight, multiset of values> //processing(sorting) input for (int i = 0; i<N; i++) { int V, W, K; cin >> V >> W >> K; int maxQ = S/W; while (items[W].size() < maxQ && K>0) { items[W].insert(V); K--; } while (items[W].size() == maxQ && K>0 && V > *items[W].begin()) { items[W].erase(*items[W].begin()); items[W].insert(V); K--; } } // Converting multiset to a vector vector<vector<int>> choices(S + 1); for (int i = 1; i <= S; i++) { if (items.find(i) != items.end()) { choices[i].assign(items[i].rbegin(), items[i].rend()); } } //knapsack DP for (int i = 1; i<S+1; i++) { vector<int> values = choices[i]; for (int k = 0; k<values.size(); k++) { for (int x = S; x>=0; x--) { if (x-i >= 0) { dp[x] = max(dp[x], dp[x-i] + values[k]); } } } } ll ans = 0; for (int x = 0; x<S+1; x++) { ans = max(ans, dp[x]); } cout << ans << "\n"; }

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

knapsack.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
knapsack.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
knapsack.java:4: error: class, interface, or enum expected
typedef long long ll;
^
knapsack.java:7: error: class, interface, or enum expected
int main() {
^
knapsack.java:9: error: class, interface, or enum expected
    cin.tie(0); cout.tie(0);
    ^
knapsack.java:9: error: class, interface, or enum expected
    cin.tie(0); cout.tie(0);
                ^
knapsack.java:10: error: class, interface, or enum expected
    int S, N;
    ^
knapsack.java:11: error: class, interface, or enum expected
    cin >> S >> N;
    ^
knapsack.java:12: error: class, interface, or enum expected
    vector<ll> dp(S+1);
    ^
knapsack.java:13: error: class, interface, or enum expected
    unordered_map<int ,multiset<ll>> items; //<weight, multiset of values>
    ^
knapsack.java:16: error: class, interface, or enum expected
    for (int i = 0; i<N; i++) {
    ^
knapsack.java:16: error: class, interface, or enum expected
    for (int i = 0; i<N; i++) {
                    ^
knapsack.java:16: error: class, interface, or enum expected
    for (int i = 0; i<N; i++) {
                         ^
knapsack.java:18: error: class, interface, or enum expected
        cin >> V >> W >> K;
        ^
knapsack.java:20: error: class, interface, or enum expected
        int maxQ = S/W;
        ^
knapsack.java:21: error: class, interface, or enum expected
        while (items[W].size() < maxQ && K>0) {
        ^
knapsack.java:23: error: class, interface, or enum expected
            K--;
            ^
knapsack.java:24: error: class, interface, or enum expected
        }
        ^
knapsack.java:27: error: class, interface, or enum expected
            items[W].insert(V);
            ^
knapsack.java:28: error: class, interface, or enum expected
            K--;
            ^
knapsack.java:29: error: class, interface, or enum expected
        }
        ^
knapsack.java:35: error: class, interface, or enum expected
    for (int i = 1; i <= S; i++) {
    ^
knapsack.java:35: error: class, interface, or enum expected
    for (int i = 1; i <= S; i++) {
                    ^
knapsack.java:35: error: class, interface, or enum expected
    for (int i = 1; i <= S; i++) {
                            ^
knapsack.java:38: error: class, interface, or enum expected
        }
        ^
knapsack.java:42: error: class, interface, or enum expected
    for (int i = 1; i<S+1; i++) {
                    ^
knapsack.java:42: error: class, interface, or enum expected
    for (int i = 1; i<S+1; i++) {
                           ^
knapsack.java:44: error: class, interface, or enum expected
        for (int k = 0; k<values.size(); k++) {
        ^
knapsack.java:44: error: class, interface, or enum expected
        for (int k = 0; k<values.size(); k++) {
                        ^
knapsack.java:44: error: class, interface, or enum expected
        for (int k = 0; k<values.size(); k++) {
                                         ^
knapsack.java:45: error: class, interface, or enum expected
            for (int x = S; x>=0; x--) {
                            ^
knapsack.java:45: error: class, interface, or enum expected
            for (int x = S; x>=0; x--) {
                                  ^
knapsack.java:48: error: class, interface, or enum expected
                }
                ^
knapsack.java:54: error: class, interface, or enum expected
    for (int x = 0; x<S+1; x++) {
    ^
knapsack.java:54: error: class, interface, or enum expected
    for (int x = 0; x<S+1; x++) {
                    ^
knapsack.java:54: error: class, interface, or enum expected
    for (int x = 0; x<S+1; x++) {
                           ^
knapsack.java:56: error: class, interface, or enum expected
    }
    ^
knapsack.java:58: error: class, interface, or enum expected
}
^
38 errors