Submission #1162322

#TimeUsernameProblemLanguageResultExecution timeMemory
1162322SP_CaramenStove (JOI18_stove)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> arrival_times(n); for (int i = 0; i < n; ++i) { cin >> arrival_times[i]; } sort(arrival_times.begin(), arrival_times.end()); long long min_total_time = -1; // Function to calculate the total stove time for a given set of turn-on times auto calculate_total_time = [&](constvector<int>&turn_on_times) { long long total_time = 0; int guest_index = 0; int turn_on_index = 0; while (guest_index < n) { if (turn_on_index < turn_on_times.size() && arrival_times[guest_index] >= turn_on_times[turn_on_index]) { // Stove is turned on before or at the same time as the guest arrives total_time += (arrival_times[guest_index] + 1) - arrival_times[guest_index]; // Stove on for 1 unit of time guest_index++; } else { // Find the next turn-on time that is after the guest's arrival bool found_next = false; for (int j = 0; j < turn_on_times.size(); ++j){ if(turn_on_times[j] > arrival_times[guest_index]){ turn_on_index = j; found_next = true; break; } } if(found_next){ } else { // If no more turn on available for this guest, it is an invalid arrangement, so we return a big number return (long long)1e18; } } if(turn_on_index < turn_on_times.size()){ turn_on_index++; } } return total_time; }; // Generate all possible combinations of K turn-on times vector<int> turn_on_times(k); function<void(int, int)> generate_combinations = [&](intindex,intstart) { if (index == k) { // Sort the turn-on times sort(turn_on_times.begin(), turn_on_times.end()); // Calculate the total stove time for this combination long long current_total_time = calculate_total_time(turn_on_times); // Update the minimum total time if (min_total_time == -1 || current_total_time < min_total_time) { min_total_time = current_total_time; } return; } for (int i = start; i <= arrival_times[n-1]; ++i) { turn_on_times[index] = i; generate_combinations(index + 1, i); } }; // Start generating combinations from time 0 if(k > 0){ generate_combinations(0, 0); } else { min_total_time = (long long)1e18; } // If K is 0, check if any guest visits if (k == 0){ bool any_guest = false; for (int i = 0; i < n; i++){ any_guest = true; break; } if (any_guest) { cout << (long long)1e18 << endl; return 0; } else { cout << 0 << endl; return 0; } } if(min_total_time == (long long)1e18){ // If no K diêm can serve all guests, consider serving each guest min_total_time = n; if (k < 1){ min_total_time = (long long)1e18; } } cout << min_total_time << endl; return 0; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:19:37: error: 'constvector' has not been declared
   19 |     auto calculate_total_time = [&](constvector<int>&turn_on_times) {
      |                                     ^~~~~~~~~~~
stove.cpp:19:48: error: expected ',' or '...' before '<' token
   19 |     auto calculate_total_time = [&](constvector<int>&turn_on_times) {
      |                                                ^
stove.cpp: In lambda function:
stove.cpp:25:33: error: 'turn_on_times' was not declared in this scope; did you mean 'turn_on_index'?
   25 |             if (turn_on_index < turn_on_times.size() && arrival_times[guest_index] >= turn_on_times[turn_on_index]) {
      |                                 ^~~~~~~~~~~~~
      |                                 turn_on_index
stove.cpp:48:32: error: 'turn_on_times' was not declared in this scope; did you mean 'turn_on_index'?
   48 |             if(turn_on_index < turn_on_times.size()){
      |                                ^~~~~~~~~~~~~
      |                                turn_on_index
stove.cpp: In function 'int main()':
stove.cpp:59:13: error: 'intindex' has not been declared
   59 |         [&](intindex,intstart) {
      |             ^~~~~~~~
stove.cpp:59:22: error: 'intstart' has not been declared
   59 |         [&](intindex,intstart) {
      |                      ^~~~~~~~
stove.cpp: In lambda function:
stove.cpp:60:19: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator=='
   60 |         if (index == k) {
      |             ~~~~~~^~~~
stove.cpp:65:64: error: no match for call to '(main()::<lambda(int)>) (std::vector<int>&)'
   65 |             long long current_total_time = calculate_total_time(turn_on_times);
      |                                            ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
stove.cpp:19:33: note: candidate: 'main()::<lambda(int)>'
   19 |     auto calculate_total_time = [&](constvector<int>&turn_on_times) {
      |                                 ^
stove.cpp:19:33: note:   no known conversion for argument 1 from 'std::vector<int>' to 'int'
stove.cpp:74:22: error: 'start' was not declared in this scope
   74 |         for (int i = start; i <= arrival_times[n-1]; ++i) {
      |                      ^~~~~
stove.cpp:75:26: error: no match for 'operator[]' (operand types are 'std::vector<int>' and '<unresolved overloaded function type>')
   75 |             turn_on_times[index] = i;
      |                          ^
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from stove.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::const_reference = const int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
stove.cpp:76:41: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator+'
   76 |             generate_combinations(index + 1, i);
      |                                   ~~~~~~^~~