제출 #1198711

#제출 시각아이디문제언어결과실행 시간메모리
1198711phantomstar3.14Knapsack (NOI18_knapsack)C++20
컴파일 에러
0 ms0 KiB
///////////////////////////////////////////
//                                       //
//     CODE BY THE phantomstar3.14       //
//                                       //
///////////////////////////////////////////


#include <bits/stdc++.h>
using namespace std;

#define int long long int
#define ull unsigned long long
 
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
 
constexpr int V = 1E9;
constexpr int MAXN=1e9;
const int mod=1e9+7;
vector<int> primes;
vector<bool>prime(MAXN+1,true);

void sieve() 
{
    prime[0] = prime[1] = false;

    for (int p = 2; p * p < MAXN; p++) 
    {
        if (prime[p]) 
        {
            for (int i = p * p; i < MAXN; i += p)
                prime[i] = false;
        }
    }

    for (int p = 2; p < MAXN; p++) {
        if (prime[p])
            primes.push_back(p);
    }
} 
void solve() {
    int s,n;
    cin >> s >> n ;
    map<vector<pair<int,int>> > v;
    vector<vector<int>> dp(n, vector<int> s(n,0));
    for(int i=0; i<n; i++)
    {
        int val, weight, k;
        cin>>val>>weight>>k;
        if(i==0)
        {
            for(int j=weight; j<=min(k*weight,s); j+=weight)
                dp[i][j]=dp[i][j-weight]+val;
        }
        if(weight<=s)
            v[weight].push_back({val, k});
    }
    int curr=1;
    for(auto [w, vec] : v)
    {
        if(curr==n) break;
        sort(vec.rbegin(), vec.rend());
        for(int j=0; j<=s; j++)
        {
            dp[curr][j]=max(dp[curr][j], dp[curr-1][j]);
            if(j<w)
                continue;
            int num=1;
            int weight=w;
            int idx=0;
            int total =0;
            while(num*weight <= s and idx<vec.size())
            {
                dp[curr][j]=max(dp[curr][j], dp[curr][j-num*weight]+num*vec[idx].first);
                num++;
                if(num > vec[idx].second)
                {
                    idx++;
                    num=1;
                }
            }
        }
        curr++;
    }
    int ans=0;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<=s; j++)
            ans=max(ans, dp[i][j]);
    }
    cout<<ans<<"\n";
}
 
int32_t main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    auto begin = std::chrono::high_resolution_clock::now();
    //freopen("poetry.in", "r", stdin);
    //freopen("poetry.out", "w", stdout);
    int t=1;
    //cin >> t;
    
    while (t--) 
    {
        solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
    return 0;
}

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:43:31: error: wrong number of template arguments (1, should be at least 2)
   43 |     map<vector<pair<int,int>> > v;
      |                               ^
In file included from /usr/include/c++/11/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:81,
                 from knapsack.cpp:8:
/usr/include/c++/11/bits/stl_map.h:100:11: note: provided for 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  100 |     class map
      |           ^~~
knapsack.cpp:44:43: error: expected primary-expression before 's'
   44 |     vector<vector<int>> dp(n, vector<int> s(n,0));
      |                                           ^
knapsack.cpp:55:14: error: invalid types 'int[long long int]' for array subscript
   55 |             v[weight].push_back({val, k});
      |              ^
knapsack.cpp:58:25: error: 'begin' was not declared in this scope
   58 |     for(auto [w, vec] : v)
      |                         ^
knapsack.cpp:58:25: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95,
                 from knapsack.cpp:8:
/usr/include/c++/11/valarray:1228:5: note:   'std::begin'
 1228 |     begin(const valarray<_Tp>& __va) noexcept
      |     ^~~~~
In file included from /usr/include/c++/11/string_view:48,
                 from /usr/include/c++/11/bits/basic_string.h:48,
                 from /usr/include/c++/11/string:55,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from knapsack.cpp:8:
/usr/include/c++/11/bits/ranges_base.h:561:44: note:   'std::ranges::__cust::begin'
  561 |     inline constexpr __cust_access::_Begin begin{};
      |                                            ^~~~~
In file included from /usr/include/c++/11/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:129,
                 from knapsack.cpp:8:
/usr/include/c++/11/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
In file included from /usr/include/c++/11/bits/stl_iterator_base_types.h:71,
                 from /usr/include/c++/11/bits/stl_algobase.h:65,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from knapsack.cpp:8:
/usr/include/c++/11/bits/iterator_concepts.h:949:10: note:   'std::ranges::__cust_access::begin'
  949 |     void begin(const auto&) = delete;
      |          ^~~~~
knapsack.cpp:58:25: error: 'end' was not declared in this scope
   58 |     for(auto [w, vec] : v)
      |                         ^
knapsack.cpp:58:25: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95,
                 from knapsack.cpp:8:
/usr/include/c++/11/valarray:1255:5: note:   'std::end'
 1255 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
In file included from /usr/include/c++/11/string_view:48,
                 from /usr/include/c++/11/bits/basic_string.h:48,
                 from /usr/include/c++/11/string:55,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from knapsack.cpp:8:
/usr/include/c++/11/bits/ranges_base.h:562:42: note:   'std::ranges::__cust::end'
  562 |     inline constexpr __cust_access::_End end{};
      |                                          ^~~
In file included from /usr/include/c++/11/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:129,
                 from knapsack.cpp:8:
/usr/include/c++/11/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~
In file included from /usr/include/c++/11/string_view:48,
                 from /usr/include/c++/11/bits/basic_string.h:48,
                 from /usr/include/c++/11/string:55,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from knapsack.cpp:8:
/usr/include/c++/11/bits/ranges_base.h:136:10: note:   'std::ranges::__cust_access::end'
  136 |     void end(const auto&) = delete;
      |          ^~~