이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
//#define int long long
//#include <iostream>
//#include <algorithm>
int currsum;
bool checkers(int x, int K, vector<pair<int,int>> &ans, int A)
//return false if adding would make it too large
//return true if not and insert x into the vector
//ans : {index, value} pair
{
int ants;
int temp1 = skim(x);
int cantake = (2 * A) - currsum;
if ((currsum + (temp1 - ans[K].second)) > (2 * A))
{
return false;
}
else
{
int hi = K, lo = 1, mid;
while (hi > lo)
{
//printf("stuck in checkers\n");
mid = (hi + lo)/2;
if (((temp1 - ans[mid].second) <= cantake)) //won't exceed : go lower
{
//printf("replacing %d is ok\n",mid);
hi = mid;
}
else
{
lo = mid + 1;
}
}
currsum += (temp1 - ans[lo].second);
//cout << "x : " << x << "\n";
ans[lo] = {x,temp1};
//printf("replaced %d", lo);
}
//printf ("this is currsum now : %d",currsum);
sort(ans.begin() + 1, ans.end());
return true;
}
void solve(int N, int K, long long A, int S)
{
vector<pair<int,int>>ans(K + 1);
int temp1,temp2;
for (int a = 1; a <= K; a++)
{
temp2 = skim(a);
ans[a] = {a,temp2};
currsum += temp2;
}
if (currsum > (2 * A))
{
impossible();
}
vector<int>kokonut;
if ((currsum >= A) && (currsum <= (2 * A)))
{
for (int a = 1; a <= K; a++)
{
kokonut.push_back(ans[a].first);
}
answer(kokonut);
}
int hi = N,lo = K + 1,mid;
int anss;
while (hi >= lo)
{
//printf("stuck in solve\n");
mid = (hi + lo)/2;
if (checkers(mid, K, ans, A)) //keyi
{
anss = mid;
lo = mid + 1;
}
else
{
hi = mid - 1;
}
//printf("\n%d is between %d and %d", currsum, A, (2 * A));
if ((currsum >= A) && (currsum <= (2 * A)))
{
for (int a = 1; a <= K; a++)
{
kokonut.push_back(ans[a].first);
}
answer(kokonut);
}
}
//printf("is this one\n");
impossible();
}
컴파일 시 표준 에러 (stderr) 메시지
books.cpp: In function 'bool checkers(int, int, std::vector<std::pair<int, int> >&, int)':
books.cpp:16:9: warning: unused variable 'ants' [-Wunused-variable]
16 | int ants;
| ^~~~
books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:55:9: warning: unused variable 'temp1' [-Wunused-variable]
55 | int temp1,temp2;
| ^~~~~
books.cpp:79:9: warning: variable 'anss' set but not used [-Wunused-but-set-variable]
79 | int anss;
| ^~~~
# | 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... |