제출 #489705

#제출 시각아이디문제언어결과실행 시간메모리
489705arwaeystoamnegA Difficult(y) Choice (BOI21_books)C++17
100 / 100
3 ms1096 KiB
// EXPLOSION! #define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> #include<unordered_set> #include<unordered_map> #include<chrono> using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef pair<ll, ll> pll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pair<int, int>> vpi; typedef vector<pair<ll, ll>> vpll; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define mp make_pair #define rsz resize #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define f first #define s second #define cont continue //#define endl '\n' //#define ednl '\n' #define test int testc;cin>>testc;while(testc--) #define pr(a, b) trav(x,a)cerr << x << b; cerr << endl; #define message cout << "Hello World" << endl; const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!! const ll linf = 4000000000000000000LL; const ll inf = 1000000007;//998244353 void pv(vi a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vll a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vector<vi>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); cout << endl; } }void pv(vector<vll>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); }cout << endl; }void pv(vector<string>a) { trav(x, a)cout << x << endl; cout << endl; } void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef arwaeystoamneg if (sz(s)) { freopen((s + ".in").c_str(), "r", stdin); if (s != "test1") freopen((s + ".out").c_str(), "w", stdout); } #endif } #ifndef arwaeystoamneg #include<books.h> #endif #ifdef arwaeystoamneg void result(string x) { cout << x << endl; exit(0); } namespace { int N, K, S, sUsed; long long A; vector<long long> seq; } void impossible() { result("Impossible (not checked): %d book(s) skimmed"); exit(0); } long long skim(int pos) { printf("skim(%d): ", pos); if (pos<1 || pos>N) result("Invalid skim"); printf("%lld\n", seq[pos]); sUsed++; if (sUsed > S) result("Out of books to skim"); return seq[pos]; } void answer(vector<int> v) { printf("answer({"); for (int i = 0; i < (int)v.size(); ++i) { printf("%d", v[i]); if (i + 1 != (int)v.size()) printf(", "); } printf("})\n"); if ((int)v.size() != K) result("Invalid answer"); ll sum = 0; for (auto x : v) { if (x<1 || x>N) result("Invalid answer"); sum += seq[x]; } if (sum < A || 2 * A < sum) result("Wrong answer"); result("Correct: %d book(s) skimmed"); exit(0); } #endif vll a; void solve(int n, int k, ll A, int s) { a.rsz(n); ll s1 = 0; F0R(i, k)a[i] = skim(i + 1); s1 = accumulate(all(a), 0LL); if (s1 >= A) { if (s1 > 2 * A)impossible(); else { vi ans; F0R(i, k)ans.pb(i + 1); answer(ans); } } int l = 0, r = n - 1; while (l < r) { int m = (l + r + 1) / 2; if (skim(m + 1) < A) { l = m; } else { r = m - 1; } } assert(k <= l); F0R(i, k)a[l - i] = skim(l - i + 1); ll s2 = 0; F0R(i, k)s2 += a[l - i]; if (s2 <= 2 * A) { if (s2 >= A) { vi ans; F0R(i, k)ans.pb(l - i + 1); answer(ans); } else { if (l == n - 1)impossible(); s1 -= a[k - 1]; s1 += skim(l + 2); if (s1 > 2 * A)impossible(); vi ans = { l + 2 }; F0R(i, k - 1)ans.pb(i + 1); answer(ans); } } F0R(i, k) { s1 -= a[i]; s1 += a[l - i]; if (s1 >= A) { vi ans; FOR(j, i + 1, k)ans.pb(j + 1); F0R(j, i + 1)ans.pb(l - j + 1); answer(ans); } } assert(0); } #ifdef arwaeystoamneg int main() { setIO("test1"); if (scanf("%d %d %lld %d", &N, &K, &A, &S) != 4) result("Invalid input"); seq.resize(N + 1); for (int i = 1; i <= N; ++i) { if (scanf("%lld", &(seq[i])) != 1) result("Invalid input"); if (i > 1 && seq[i] <= seq[i - 1]) result("Invalid input"); } solve(N, K, A, S); result("No answer"); } #endif
#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...