Submission #470104

#TimeUsernameProblemLanguageResultExecution timeMemory
470104Haruto810198A Difficult(y) Choice (BOI21_books)C++17
0 / 100
1 ms200 KiB
#include <bits/stdc++.h> #include "books.h" #define ll long long #define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d)) #define vi vector<int> #define pb push_back using namespace std; // // --- Sample implementation for the task books --- // // To compile this program with the sample grader, place: // books.h books_sample.cpp sample_grader.cpp // in a single folder and run: // g++ books_sample.cpp sample_grader.cpp // in this folder. // const int MAX = 100010; ll arr[MAX]; ll sum[11]; // sum[i] : pref = i, suf = k - i vector<int> res; int query(int id){ if(arr[id] == 0){ arr[id] = skim(id); } return arr[id]; } void solve(int N, int K, ll A, int Q){ FOR(i, 1, K, 1){ query(i); query(N-i+1); } FOR(i, 0, K, 1){ // sum[i] FOR(j, 1, i, 1){ sum[i] += query(j); } for(int j = N; j > N - (K - i); j--){ sum[i] += query(j); } } if(sum[0] < A or sum[K] > 2*A){ impossible(); return; } FOR(i, 0, K, 1){ if(A <= sum[i] and sum[i] <= 2*A){ FOR(j, 1, i, 1){ res.pb(j); } for(int j = N; j > N - (K - i); j--){ res.pb(j); } answer(res); return; } } int sum_id; int L, R, mid; for(int i = K; i >= 0; i--){ if(sum[i] < A){ sum_id = i; L = sum_id; R = L + (N - K); } } while(L < R){ mid = (L + R) / 2; query(mid); int new_sum = sum[sum_id] - arr[sum_id] + arr[mid]; if(new_sum >= A){ R = mid; } else{ L = mid + 1; } } FOR(j, 1, sum_id - 1, 1){ res.pb(j); } for(int j = N; j > N - (K - sum_id); j--){ res.pb(j); } res.pb(L); answer(res); return; }

Compilation message (stderr)

books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:80:18: warning: 'R' may be used uninitialized in this function [-Wmaybe-uninitialized]
   80 |         mid = (L + R) / 2;
      |               ~~~^~~~
books.cpp:6:41: warning: 'sum_id' may be used uninitialized in this function [-Wmaybe-uninitialized]
    6 | #define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
      |                                         ^~
books.cpp:68:9: note: 'sum_id' was declared here
   68 |     int sum_id;
      |         ^~~~~~
#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...