Submission #1076392

#TimeUsernameProblemLanguageResultExecution timeMemory
1076392dostsA Difficult(y) Choice (BOI21_books)C++17
100 / 100
2 ms1368 KiB
//Dost SEFEROĞLU #include <bits/stdc++.h> #include "books.h" using namespace std; #define int long long #define pii pair<int,int> #define ff first #define ss second #define sp << " " << #define all(cont) cont.begin(),cont.end() #define vi vector<int> using namespace std; void solve(int32_t N, int32_t K, long long A, int32_t S) { vi memory(N+1,0); auto get = [&](int p) -> int { if (memory[p]) return memory[p]; return memory[p] = skim(p); }; int sm = 0; for (int i=1;i<=K-1;i++) sm+=get(i); int l = K; int r = N; while (l<=r) { int m = (l+r) >> 1; if (get(m)+sm >= A) r = m-1; else l = m+1; } if (l<=N && get(l)+sm >= A && get(l)+sm <= 2*A) { vector<int32_t> v; for (int j=1;j<=K-1;j++) v.push_back(j); v.push_back(l); answer(v); return; } sm+=get(K); int ptr = K; while (sm < A) { if (ptr < 1) { impossible(); return; } sm-=get(ptr); sm+=get(l-1-(K-ptr)); ptr--; } if (sm >= A && sm <= 2*A) { vector<int32_t> v; for (int i=1;i<=ptr;i++) v.push_back(i); for (int j=K-ptr;j>=1;j--) v.push_back((l-1)-j+1); answer(v); } 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...