Submission #430620

#TimeUsernameProblemLanguageResultExecution timeMemory
430620TryMaxCarnival Tickets (IOI20_tickets)C++17
Compilation error
0 ms0 KiB
#include "tickets.h" #ifdef LOCAL #include "grader.cpp" #endif // LOCAL #include <bits/stdc++.h> #define f first #define s second #define ll long long #define pb push_back using namespace std; const int N = 2e5 + 10; int have[N]; ll cost(vector<int> a){ sort(a.begin(), a.end()); ll ans = 0; for(int i = 0; i < n / 2; ++i) ans += a[n / 2] - a[i]; for(int i = n / 2; i < n; ++i) ans += a[i] - a[n / 2]; return ans; } ll find_maximum(int k, vector<vector<int>> x){ int n = x.size(); int m = x[0].size(); vector<pair<int, pair<int, int>>> a; for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j) a.pb({x[i][j], {i, j}}); sort(a.begin(), a.end()); vector<vector<int>> ans; ans.resize(n); for(int i = 0; i < n; ++i){ ans[i].resize(m); for(int j = 0; j < m; ++j) ans[i][j] = -1; } int num = 0, ans1 = 0; vector<int> now; int l = 0, r = a.size() - 1; while(num < k){ while(l < r && have[a[l].s.f]) ++l; ans[a[l].s.f][a[l].s.s] = num; now.pb(a[l].f); have[a[l].s.f] = 1; while(l < r && have[a[r].s.f]) --r; ans[a[r].s.f][a[r].s.s] = num; have[a[r].s.f] = 1; now.pb(a[r].f); if(now.size() == n){ ans1 += cost(now); now.clear(); for(int i = 0; i < n; ++i) have[i] = 0; ++num; } ++l, --r; } allocate_tickets(ans); return ans1; } /* 2 3 2 0 2 5 1 1 3 7 0 -1 1 -1 1 0 4 2 1 5 9 1 4 3 6 2 7 12 -1 0 0 -1 0 -1 -1 0 */

Compilation message (stderr)

tickets.cpp: In function 'long long int cost(std::vector<int>)':
tickets.cpp:21:24: error: 'n' was not declared in this scope
   21 |     for(int i = 0; i < n / 2; ++i)
      |                        ^
tickets.cpp:23:17: error: 'n' was not declared in this scope
   23 |     for(int i = n / 2; i < n; ++i)
      |                 ^
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:57:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |         if(now.size() == n){
      |            ~~~~~~~~~~~^~~~