제출 #1253146

#제출 시각아이디문제언어결과실행 시간메모리
1253146anfi축제 (IOI25_festival)C++20
컴파일 에러
0 ms0 KiB
#include "festival.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second typedef long long ll; vector<int> max_coupons(int A, vector<int> P, vector<int> T){ int cost = A, n = P.size(); vector<int> ans,use(N, 0); vector<pair<int,int>> mp[5]; for(int i = 0; i < N; i++){ mp[T[i]].push_back({P[i],i}); } for(inti = 1; i <= 4; i++) sort(mp[i].begin(), mp[i].end()); priority_queue<int, vector<int>, greater<int>> pq; struct item{ int t, idx; ll p; } struct cmp{ bool operator()(item const &a, item const &b){ if(a.t != b.t) return a.t < b.t; return a.p > b.p; } }; priority_queue<item, vector<item>, cmp> pq; int pr2 = 0, pr3 = 0, pr4 = 0; int sz2 = mp[2].size(), sz3 = mp[3].size(), sz4 = mp[4].size(); auto hitung = [&](int t, int &pt, int sz){ while(pt < sz && mp[t][pt].fi <= cost){ pq.push({t, mp[t][pt].se, mp[t][pt].fi}); pt++; } }; hitung(4, pr4, sz4); hitung(3, pr3, sz3); hitung(2, pr2, sz2); while(!pq.empty()){ auto it = pq.top(); pq.pop(); if(use[it.idx]) continue; use[it.idx] = 1; cost = (cost-it.p)*it.t; ans.push_back(it.idx); hitung(4, pr4, sz4); hitung(3, pr3, sz3); hitung(2, pr2, sz2); } for(auto &pr : mp[1]){ if(pr.fi <= cost){ cost = (cost-pr.fi); ans.push_back(pr.se); }else break; } return ans; }

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

festival.cpp: In function 'std::vector<int> max_coupons(int, std::vector<int>, std::vector<int>)':
festival.cpp:10:25: error: 'N' was not declared in this scope
   10 |     vector<int> ans,use(N, 0);
      |                         ^
festival.cpp:15:9: error: 'inti' was not declared in this scope; did you mean 'int'?
   15 |     for(inti = 1; i <= 4; i++) sort(mp[i].begin(), mp[i].end());
      |         ^~~~
      |         int
festival.cpp:15:19: error: 'i' was not declared in this scope
   15 |     for(inti = 1; i <= 4; i++) sort(mp[i].begin(), mp[i].end());
      |                   ^
festival.cpp:20:6: error: expected ';' after struct definition
   20 |     }
      |      ^
      |      ;
festival.cpp:27:45: error: conflicting declaration 'std::priority_queue<max_coupons(int, std::vector<int>, std::vector<int>)::item, std::vector<max_coupons(int, std::vector<int>, std::vector<int>)::item>, max_coupons(int, std::vector<int>, std::vector<int>)::cmp> pq'
   27 |     priority_queue<item, vector<item>, cmp> pq;
      |                                             ^~
festival.cpp:16:52: note: previous declaration as 'std::priority_queue<int, std::vector<int>, std::greater<int> > pq'
   16 |     priority_queue<int, vector<int>, greater<int>> pq;
      |                                                    ^~
festival.cpp: In lambda function:
festival.cpp:33:20: error: no matching function for call to 'std::priority_queue<int, std::vector<int>, std::greater<int> >::push(<brace-enclosed initializer list>)'
   33 |             pq.push({t, mp[t][pt].se, mp[t][pt].fi});
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:86,
                 from festival.cpp:2:
/usr/include/c++/11/bits/stl_queue.h:640:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = int; _Sequence = std::vector<int>; _Compare = std::greater<int>; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = int]'
  640 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/11/bits/stl_queue.h:640:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const int&'}
  640 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_queue.h:648:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(std::priority_queue<_Tp, _Sequence, _Compare>::value_type&&) [with _Tp = int; _Sequence = std::vector<int>; _Compare = std::greater<int>; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = int]'
  648 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/11/bits/stl_queue.h:648:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<int, std::vector<int>, std::greater<int> >::value_type&&' {aka 'int&&'}
  648 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
festival.cpp: In function 'std::vector<int> max_coupons(int, std::vector<int>, std::vector<int>)':
festival.cpp:43:19: error: request for member 'idx' in 'it', which is of non-class type 'int'
   43 |         if(use[it.idx]) continue;
      |                   ^~~
festival.cpp:44:16: error: request for member 'idx' in 'it', which is of non-class type 'int'
   44 |         use[it.idx] = 1;
      |                ^~~
festival.cpp:45:25: error: request for member 'p' in 'it', which is of non-class type 'int'
   45 |         cost = (cost-it.p)*it.t;
      |                         ^
festival.cpp:45:31: error: request for member 't' in 'it', which is of non-class type 'int'
   45 |         cost = (cost-it.p)*it.t;
      |                               ^
festival.cpp:46:26: error: request for member 'idx' in 'it', which is of non-class type 'int'
   46 |         ans.push_back(it.idx);
      |                          ^~~