이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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.
//
const int maxn = 1e5+5;
long long d[maxn], l, r;
/*vector <long long> v;
void impossible(){
cout << -1 << endl;
return;
}
long long skim (int in){
return v[in - 1];
}
void answer (vector <int> ans){
for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
cout << endl;
return;
}*/
int find (int k, int N){
if (N < k) return -1;
long long suma = 0;
for (int i = N; i >= N - k + 1; i--) suma += d[i];
if (suma < l) return -1;
if (suma <= r) return N;
suma = 0;
for (int i = 1; i <= k; i++) suma += d[i];
if (suma > r) return -1;
if (suma >= l) return k;
for (int i = k + 1; i <= N; i++){
suma -= d[i - k - 1];
suma += d[i];
if (suma >= l) return i;
}
}
void solve(int N, int K, long long A, int S) {
for (int i = 1; i <= N; i++) d[i] = skim(i);
vector <int> ans;
l = A, r = 2 * A;
for (int i = 0; i < K; i++){
int in = find(K - i, N);
//cout << i << " " << in << endl;
if (in == -1) impossible();
ans.push_back(in);
l-=d[in], r-=d[in];
N = in - 1;
}
//cout << "l r " << l << " " << r << endl;
if (l <= 0 and r >= 0) answer(ans);
else impossible();
}
/*
int main (void){
v.push_back(8), v.push_back(10), v.push_back(12), v.push_back(43), v.push_back(45), v.push_back(46), v.push_back(48), v.push_back(50);
solve(8, 3, 32, 8);
return 0;
}*/
컴파일 시 표준 에러 (stderr) 메시지
books.cpp: In function 'int find(int, int)':
books.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
52 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |