이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#include "books.h"
#else
long long skim(int i) {
cout << "? " << i << endl;
int val;
cin >> val;
return val;
}
void answer(vector<int> v) {
for (auto to : v) {
cout << to << ' ';
}
cout << endl;
}
void impossible() {
cout << "NO WAY" << endl;
}
#endif // LOCAL
#define pb push_back
#define ll long long
void solve(int n, int k, ll a, int s) {
int l = -1, r = n;
while (r - l > 1) {
int mid = (r + l) / 2;
if (skim(mid + 1) >= a) {
r = mid;
} else {
l = mid;
}
}
ll sum = 0;
vector<int> arr;
map<int, ll> mp;
for (int j = 0; j < k - 1; j++) {
ll res = skim(j + 1);
mp[j + 1] = res;
sum += skim(res);
arr.pb(j + 1);
}
vector<int> rem_arr = arr;
ll val = skim(k), rem_sum = sum;
mp[k] = val;
sum += val;
arr.pb(k);
if (a <= sum && sum <= 2 * a) {
answer(arr);
return;
}
if (r >= k) {
vector<int> nw;
for (int j = 0; j < k; j++) {
sum -= mp[k - j];
sum += skim(r - j);
nw.pb(r - j);
arr.pop_back();
if (a <= sum && sum <= 2 * a) {
for (auto to : nw) arr.pb(to);
answer(arr);
return;
}
}
}
sum = rem_sum, arr = rem_arr;
if (r < n) {
if (r >= k - 1) {
ll valr = skim(r + 1);
sum += valr;
if (a <= sum && sum <= 2 * a) {
arr.pb(r + 1);
answer(arr);
return;
}
}
}
impossible();
}
#ifdef LOCAL
signed main() {
int n, k, s;
long long a;
cin >> n >> k >> a >> s;
solve(n, k, a, s);
}
#endif // LOCAL
# | 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... |