Submission #1073962

#TimeUsernameProblemLanguageResultExecution timeMemory
1073962deeraHoliday (IOI14_holiday)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; long long findMaxAttraction(int n, int start, int d, int attraction[]) { if (d == 0) {return 0;} if (d == 1) {return attraction[start];} if (n <= 20) { // iterate over all the subtasks long long max_ans = 0; long long ans = 0; for (int32_t i = 0; i < (1 << n); i++) { int len = 32 - (__builtin_clz(i) + __builtin_ctz(i)) - 1; int a = __builtin_ctz(i); int b = 31 - __builtin_clz(i); int cost = __builtin_popcount(i) + len + min(abs(a - start), abs(b - start)); // if (i == 30) { // for (int j = 0; j < n; j++) { // cerr << ((i & (1 << j)) ? 1 : 0) << " "; // } // cerr << endl; // cerr << cost << endl; // cerr << a << " " << b << endl; // } if (cost > d) continue; for (int j = 0; j < n; j++) { if (i & (1 << j)) { ans += attration[j]; } } max_ans = max(max_ans, ans); ans = 0; } return max_ans; } if (start == 0) { long long max_ans = 0; long long ans = 0; priority_queue<int, vector<int>, greater<int>> pq; long long sum = 0; for (int i = 0; i < n; i++) { int cost = abs(i - start); pq.push(attraction[i]); sum += attraction[i]; while (cost + pq.size() > d) { sum -= pq.top(); pq.pop(); } max_ans = max(max_ans, sum); } return max_ans; } }

Compilation message (stderr)

holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:30:28: error: 'attration' was not declared in this scope; did you mean 'attraction'?
   30 |                     ans += attration[j];
      |                            ^~~~~~~~~
      |                            attraction
holiday.cpp:52:37: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |             while (cost + pq.size() > d) {
      |                    ~~~~~~~~~~~~~~~~~^~~
holiday.cpp:43:19: warning: unused variable 'ans' [-Wunused-variable]
   43 |         long long ans = 0;
      |                   ^~~
holiday.cpp:63:1: warning: control reaches end of non-void function [-Wreturn-type]
   63 | }
      | ^