제출 #851443

#제출 시각아이디문제언어결과실행 시간메모리
851443damwuanA Difficult(y) Choice (BOI21_books)C++14
100 / 100
2 ms2648 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define bit(n,i) ((n>>i)&1) #define all(x) x.begin(),x.end() //#pragma GCC optimize("O2,unroll-loops") //#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,ssse3,sse4,popcnt") //#define int long long typedef long long ll; typedef pair<int,int> pii; typedef double ld; typedef pair<ld,ld> pdd; typedef pair<ll,ll> pll; const ll maxn=1e6+69; const ll offset=1e9; const ll block_sz=317; const ll inf=1e18; const ll mod=1e9+7; // //void __attribute__((noreturn)) __attribute__((format(printf, 1, 2))) result(const char *msg, ...) //{ // va_list args; // va_start(args, msg); // vfprintf(stderr, msg, args); // fprintf(stderr, "\n"); // va_end(args); // exit(0); //} // //namespace //{ // int N, K, S, sUsed; // long long A; // vector<long long> seq; //} // //void impossible() //{ // result("Impossible (not checked): %d book(s) skimmed", sUsed); // exit(0); //} // //long long skim(int pos) //{ // printf("skim(%d): ", pos); // if (pos<1 || pos>N) result("Invalid skim"); // printf("%lld\n", seq[pos]); // sUsed++; // if (sUsed>S) result("Out of books to skim"); // return seq[pos]; //} // //void answer(vector<int> v) //{ // printf("answer({"); // for(int i = 0; i < (int) v.size(); ++i) // { // printf("%d", v[i]); // if(i + 1 != (int) v.size()) printf(", "); // } // printf("})\n"); // // if ((int) v.size() != K) result("Invalid answer"); // ll sum = 0; // for(auto x: v) { // if (x<1 || x>N) result("Invalid answer"); // sum += seq[x]; // } // if (sum < A || 2*A<sum) result("Wrong answer"); // // result("Correct: %d book(s) skimmed", sUsed); // exit(0); //} long long sum,a[maxn],m; deque<int> gg; int _left; void sk(int pos) { if (a[pos]==0) { a[pos]=skim(pos); --_left; } } bool check(int mid,int k) { a[mid]=skim(mid); gg.pb(mid); sum+=a[mid]; while (gg.size()>k) { int x=a[gg.front()]; sum-=x; gg.pop_front(); } if (sum/gg.size()<= m) return true; else return false; } vector<int> take() { vector<int> kk; while (!gg.empty()) { kk.pb(gg.front()); gg.pop_front(); } return kk; } namespace sub12 { long long pfs[maxn]; vector<int> g; void sol(int n,int k,long long A,int s) { for1(i,1,n) a[i]=skim(i); for1(i,1,n) { pfs[i]=pfs[i-1]+a[i]; } for1(i,k,n) { if (pfs[i]-pfs[i-k]>=A && pfs[i]-pfs[i-k]<=2*A) { for1(j,i-k+1,i) g.pb(j); answer(g); } if (pfs[i]-pfs[i-k]> 2*A && pfs[i-1]-pfs[i-k-1]< A) { if (pfs[k-1]+a[i]<=2*A) { for1(j,1,k-1) g.pb(j); g.pb(i); answer(g); } else impossible(); } } } }; namespace sub3 { vector<int> g; void sol(int n,int k,long long A,int s) { _left =s; int l=1,r=n,mid; while (l<=r) { int mid=l+r>>1; sk(mid); if (a[mid]*k >= A) r=mid-1; else l=mid+1; } // cerr<<l<< " kk\n"; long long sum=0; int lim=min(l+k-1,n); for2(i,lim,lim-k+2) { sk(i); sum+=a[i]; } for2(i,lim-k+1,1) { sk(i); sum+=a[i]; if (i<lim-k+1) sum-=a[i+k]; if (sum>=A && sum <= 2*A) { for1(j,i,i+k-1) g.pb(j); answer(g); } if (sum<A || _left==0) break; } impossible(); } } namespace subfull { vector<int> g; void sol(int n,int k,long long A,int s) { // cerr<< "kk\n"; _left =s; int l=1,r=n,mid; while (l<=r) { int mid=l+r>>1; sk(mid); if (a[mid]*k >= A) r=mid-1; else l=mid+1; } // cerr<<l<< " kk\n"; long long sum=0; int lim=min(l+k-1,n); for2(i,lim,lim-k+2) { sk(i); sum+=a[i]; } for2(i,lim-k+1,1) { sk(i); sum+=a[i]; if (i<lim-k+1) sum-=a[i+k]; if (sum>=A && sum <= 2*A) { for1(j,i,i+k-1) g.pb(j); answer(g); } if (sum<A || _left==0) break; } l=1,r=n,mid; while (l<=r) { int mid=l+r>>1; sk(mid); if (a[mid] >= A) r=mid-1; else l=mid+1; } sum=a[l]; g.pb(l); for1(i,1,k-1) { sk(i); sum+=a[i]; g.pb(i); } if (sum>=A && sum <= 2*A) { answer(g); } else impossible(); } } void solve(int n,int k,long long a,int s) { subfull::sol(n,k,a,s); if (n==s) { sub12::sol(n,k,a,s); return; } if (s>=170) { sub3::sol(n,k,a,s); return; } m=(3*a/2)/k; int l=1,r=n,mid; while (l<=r) { int mid=l+r>>1; if (check(mid,k)) l=mid+1; else r= mid-1; if (gg.size()==k && sum>=a && sum <=2*a) { answer(take()); } } impossible(); } // //int main() //{ // if(scanf("%d %d %lld %d", &N, &K, &A, &S) != 4) // result("Invalid input"); // // seq.resize(N + 1); // for(int i = 1; i <= N; ++i) { // if(scanf("%lld", &(seq[i])) != 1) result("Invalid input"); // if(i>1 && seq[i]<=seq[i-1]) result("Invalid input"); // } // // solve(N, K, A, S); // // result("No answer"); //} /* 15 3 42 15 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 */

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

books.cpp: In function 'bool check(int, int)':
books.cpp:97:21: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   97 |     while (gg.size()>k)
      |            ~~~~~~~~~^~
books.cpp:103:22: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
  103 |     if (sum/gg.size()<= m) return true;
      |         ~~~~~~~~~~~~~^~~~
books.cpp: In function 'void sub3::sol(int, int, long long int, int)':
books.cpp:157:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  157 |             int mid=l+r>>1;
      |                     ~^~
books.cpp:154:21: warning: unused variable 'mid' [-Wunused-variable]
  154 |         int l=1,r=n,mid;
      |                     ^~~
books.cpp: In function 'void subfull::sol(int, int, long long int, int)':
books.cpp:196:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  196 |             int mid=l+r>>1;
      |                     ~^~
books.cpp:221:20: warning: right operand of comma operator has no effect [-Wunused-value]
  221 |         l=1,r=n,mid;
      |                    ^
books.cpp:224:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  224 |             int mid=l+r>>1;
      |                     ~^~
books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:262:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  262 |         int mid=l+r>>1;
      |                 ~^~
books.cpp:265:22: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  265 |         if (gg.size()==k && sum>=a && sum <=2*a)
      |             ~~~~~~~~~^~~
books.cpp:259:17: warning: unused variable 'mid' [-Wunused-variable]
  259 |     int l=1,r=n,mid;
      |                 ^~~
#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...