제출 #730511

#제출 시각아이디문제언어결과실행 시간메모리
730511nguyentunglamA Difficult(y) Choice (BOI21_books)C++17
100 / 100
2 ms432 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; const int N = 1e5 + 10; long long a[N]; // // --- 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. // long long Skim(int i) { if (a[i]) return a[i]; return a[i] = skim(i); } void solve(int n, int k, long long A, int s) { // // TODO implement this function int l = 1, r = n; long long v = 0; int p = n + 1; while (l <= r) { int mid = l + r >> 1; long long tmp = Skim(mid); if (tmp >= A) { v = tmp; p = mid; r = mid - 1; } else l = mid + 1; } for(int i = 1; i <= k - 1; i++) v += Skim(i); vector<int> ret; if (p <= n && k - 1 < p && v <= A * 2) { for(int i = 1; i <= k - 1; i++) ret.push_back(i); ret.push_back(p); answer(ret); } long long cur = 0; for(int i = k; i >= 1; i--) { ret.push_back(i); cur += Skim(i); if (cur > A * 2) { impossible(); return; } } if (cur >= A) answer(ret); else { --p; vector<int> add; if (p < 0 || p > n) return; while (p > k && !ret.empty()) { cur = cur - Skim(ret.back()) + Skim(p); ret.pop_back(); add.push_back(p); p--; if (cur >= A) { for(int &j : add) ret.push_back(j); answer(ret); return; } } impossible(); } }

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

books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:28:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |         int mid = l + r >> 1;
      |                   ~~^~~
#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...