Submission #406096

#TimeUsernameProblemLanguageResultExecution timeMemory
406096tqbfjotldA Difficult(y) Choice (BOI21_books)C++14
0 / 100
2 ms584 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; int cache[100005]; int n; int query(int a){ if (cache[a]!=-1) return cache[a]; return cache[a] = skim(a); } int find_val(int a, int b, int c = 1, int d = n){ if (query(c)>b) return -(c-1); if (query(c)>=a) return c; if (query(d)<a) return -d; if (query(d)<=b) return d; while (c+1<d){ int mid = (c+d)/2; int t = query(mid); if (a<=t && t<=b) return mid; if (t<a) c = mid; else d = mid; } return -c; } void solve(int N, int K, long long A, int S) { memset(cache,-1,sizeof(cache)); n = N; int en = N; vector<int> extr; for (int x = K-1; x>=0; x--){ vector<int> ans; for (int y = 0; y<x; y++){ ans.push_back(y+1); } for (auto y : extr) ans.push_back(y); int sum = 0; for (auto x : ans){ sum += query(x); } int res = find_val(A-sum,2*A-sum,x+1,en); if (res>0){ ans.push_back(res); answer(ans); return; } en = -res-1; if (x>en){ impossible(); } extr.push_back(-res); } impossible(); }
#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...