Submission #639521

#TimeUsernameProblemLanguageResultExecution timeMemory
639521BenmathA Difficult(y) Choice (BOI21_books)C++14
60 / 100
2 ms976 KiB
#include <bits/stdc++.h> #include "books.h" 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. // void solve(int N, int K, long long A, int S) { // TODO implement this function long long int so[N+1]; for(int i=0;i<=N;i++){ so[i]=-1; } int l=1; int r=N; int t1=N; int brojac=0; while(l<=r){ int mid=l+(r-l)/2; so[mid]=skim(mid); brojac++; if(so[mid]>A){ t1=min(t1,mid); r=mid-1; }else{ l=mid+1; } } if(brojac>=20){ return; } long long int sum1=0; long long int sum=0; for(int i=1;i<=K;i++){ if(so[i]==-1){ so[i]=skim(i); } sum1=sum1+so[i]; } if(sum1>2*A){ impossible(); return; }else if(sum1>=A){ vector<int>v; for(int i=1;i<=K;i++){ v.push_back(i); } answer(v); return; }else{ vector<int>v; sum=0; for(int i=1;i<K;i++){ sum=sum+so[i]; v.push_back(i); } sum=sum+so[t1]; v.push_back(t1); if(sum>=A and sum<=2*A){ answer(v); return; } vector<int>v1; sum=0; for(int i=t1-K+1;i<=t1;i++){ if(so[i]==-1){ so[i]=skim(i); } sum=sum+so[i]; v1.push_back(i); } if(sum>=A and sum<=2*A){ answer(v1); return; } vector<int>v2; sum=0; if(t1>K){ for(int i=t1-K;i<=(t1-1);i++){ if(so[i]==-1){ so[i]=skim(i); } sum=sum+so[i]; v2.push_back(i); } if(sum>=A and sum<=2*A){ answer(v2); return; } } } impossible(); /* if(t1==(N+1)){ impossible(); return; }else{ long long int sum=0; vector<int>v; for(int i=1;i<K;i++){ v.push_back(i); long long int r=so[i]; if(r==-1){ r=skim(i); so[i]=r; } sum=sum+r; } v.push_back(t1+K-1); long long int r1=so[t1+K-1]; if(r1==-1){ r1=skim(t1+K-1); } sum=sum+r1; if(sum<=2*A){ answer(v); }else{ impossible(); } } /* int n=N; long long int arr[n]; for(int i=0;i<n;i++){ arr[i]=skim(i+1); } long long int sum=0; for(int i=0;i<K;i++){ sum=sum+arr[i]; } if(sum>=A and sum<=2*A){ vector<int>v; for(int i=0;i<K;i++){ v.push_back(i+1); } answer(v); return; } for(int i=K;i<N;i++){ sum=sum+arr[i]-arr[i-K]; if(sum>=A and sum<=2*A){ vector<int>v; for(int j=i-K+1;j<=i;j++){ v.push_back(j+1); } answer(v); return; } if(sum>2*A){ sum=0; vector<int>v; for(int j=0;j<(K-1);j++){ sum=sum+arr[j]; v.push_back(j+1); } v.push_back(i+1); sum=sum+arr[i]; if(sum>=A and sum<=2*A){ answer(v); return ; }else{ impossible(); return; } } } impossible(); */ }

Compilation message (stderr)

books.cpp:136:2: warning: "/*" within comment [-Wcomment]
  136 |  /*
      |
#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...