제출 #950903

#제출 시각아이디문제언어결과실행 시간메모리
950903pccA Difficult(y) Choice (BOI21_books)C++17
100 / 100
14 ms608 KiB
#include <bits/stdc++.h> #include "books.h" #define ll long long #define pll pair<ll,ll> #define fs first #define sc second using namespace std; /* // // --- Sample implementation for the task books --- // // To compile this program with the sample grader, place: // books.h books_sample.cpp sample_grader.cpp // in a single folder and run: // g++ books_sample.cpp sample_grader.cpp // in this folder. // if (skim(2) == 42) { impossible(); } else { answer({1, 3}); } */ map<ll,ll> mp; ll ask(ll p){ if(mp.find(p) != mp.end())return mp[p]; else return mp[p] = skim(p); } void solve(int N, int K, long long A, int S) { mp.clear(); vector<pll> v; ll sum = 0; for(int i = 1;i<=K;i++){ v.push_back(pll(i,ask(i))); } ll l = 1,r = N+1; while(l+1<r){ ll mid = (l+r)>>1; if(ask(mid)>=A)r = mid; else l = mid; } if(r != N+1){ ll sum = ask(r); int cnt = 1; vector<int> ans = {r}; for(int i = 1;i<=K;i++){ if(ans.size()>=K)break; if(i == ans[0])continue; ans.push_back(i); sum += ask(i); } if(sum>=A&&sum<=A*2){ answer(ans); return; } } for(int i = 1;i<=K;i++){ if(r-i>0)v.push_back(pll(r-i,ask(r-i))); } sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); for(int i = 0;i<(1<<v.size());i++){ if(__builtin_popcount(i) != K)continue; ll sum = 0; for(int j = 0;j<v.size();j++){ if(i&(1<<j))sum += v[j].sc; } if(sum>=A&&sum<=A*2){ vector<int> ans; for(int j = 0;j<v.size();j++){ if(i&(1<<j))ans.push_back(v[j].fs); } answer(ans); return; } } impossible(); return; }

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

books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:50:22: warning: narrowing conversion of 'r' from 'long long int' to 'int' [-Wnarrowing]
   50 |   vector<int> ans = {r};
      |                      ^
books.cpp:50:22: warning: narrowing conversion of 'r' from 'long long int' to 'int' [-Wnarrowing]
books.cpp:52:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |    if(ans.size()>=K)break;
      |       ~~~~~~~~~~^~~
books.cpp:49:7: warning: unused variable 'cnt' [-Wunused-variable]
   49 |   int cnt = 1;
      |       ^~~
books.cpp:70:18: 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]
   70 |   for(int j = 0;j<v.size();j++){
      |                 ~^~~~~~~~~
books.cpp:75:19: 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]
   75 |    for(int j = 0;j<v.size();j++){
      |                  ~^~~~~~~~~
books.cpp:37:5: warning: unused variable 'sum' [-Wunused-variable]
   37 |  ll sum = 0;
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...