Submission #470100

#TimeUsernameProblemLanguageResultExecution timeMemory
470100Haruto810198A Difficult(y) Choice (BOI21_books)C++17
0 / 100
1 ms304 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; void solve(int N, int K, ll A, int Q){ FOR(i, 1, K, 1){ arr[i] = skim(i); arr[N-i+1] = skim(N-i+1); } FOR(i, 0, K, 1){ // sum[i] FOR(j, 1, i, 1){ sum[i] += arr[j]; } for(int j = N; j > N - (K - i); j--){ sum[i] += arr[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 - 1; R = L + (N - K); } } while(L < R){ mid = (L + R) / 2; arr[mid] = skim(mid); int new_sum = sum[sum_id] - arr[sum_id - 1] + 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:73:18: warning: 'R' may be used uninitialized in this function [-Wmaybe-uninitialized]
   73 |         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:61:9: note: 'sum_id' was declared here
   61 |     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...