Submission #1015852

#TimeUsernameProblemLanguageResultExecution timeMemory
1015852aykhnCarnival Tickets (IOI20_tickets)C++17
0 / 100
0 ms436 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #define inf 0x3F3F3F3F3F3F3F3F long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> answer(n, vector<int> (m, -1)); vector<vector<long long>> pre(n, vector<long long> (m, 0)), suf(n, vector<long long> (m, 0)); vector<vector<long long>> dp(n, vector<long long> (k * n / 2 + 5, -inf)), take(n, vector<long long> (k * n / 2 + 5, -1)); auto presum = [&](int i, int len) { if (!len) return 0LL; return pre[i][len - 1]; }; auto sufsum = [&](int i, int len) { if (!len) return 0LL; return suf[i][m - len]; }; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) pre[i][j] = (j ? pre[i][j - 1] : 0) + x[i][j]; for (int j = m - 1; j >= 0; j--) suf[i][j] = (j + 1 < m ? suf[i][j + 1] : 0) + x[i][j]; } vector<long long> taken(n, 0); long long s = n * k / 2; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { if (x[i][j]) break; taken[j]++; s--; } } vector<long long> l(n, 0), r(n, 0); for (int i = 0; i < n; i++) { long long x = min(s, k - taken[i]); taken[i] += x; s -= x; taken[i] = k - taken[i]; r[i] = m - taken[i]; } vector<int> o(n); iota(o.begin(), o.end(), 0); long long res = 0; for (int t = 0; t < k; t++) { sort(o.begin(), o.end(), [&](const int &a, const int &b) { return r[a] < r[b]; }); for (int i = 0; i < o.size() / 2; i++) { res += x[o[i]][r[o[i]]]; answer[o[i]][r[o[i]]] = t; r[o[i]]++; } for (int i = o.size() / 2; i < o.size(); i++) { res -= x[o[i]][l[o[i]]]; answer[o[i]][l[o[i]]] = t; l[o[i]]++; } } allocate_tickets(answer); return res; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:58:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   for (int i = 0; i < o.size() / 2; i++)
      |                   ~~^~~~~~~~~~~~~~
tickets.cpp:64:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   for (int i = o.size() / 2; i < o.size(); i++)
      |                              ~~^~~~~~~~~~
tickets.cpp:14:7: warning: variable 'presum' set but not used [-Wunused-but-set-variable]
   14 |  auto presum = [&](int i, int len)
      |       ^~~~~~
tickets.cpp:19:7: warning: variable 'sufsum' set but not used [-Wunused-but-set-variable]
   19 |  auto sufsum = [&](int i, int len)
      |       ^~~~~~
#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...