Submission #1024124

#TimeUsernameProblemLanguageResultExecution timeMemory
1024124TheWilpCarnival Tickets (IOI20_tickets)C++14
11 / 100
1 ms860 KiB
#include "tickets.h" #include <vector> #include <algorithm> using ll = long long; class name { public: int value; int i,j; bool operator<(const name& other) const { return value < other.value; } }; long long find_maximum(int k, std::vector<std::vector<int>> x) { int N = x.size(); int M = x[0].size(); std::vector<std::vector<int>> ans(x.size(),std::vector<int>(x[0].size(),-1)); std::vector<name> s; std::vector<int> group(x.size(),0); std::vector<std::vector<int>> round(k); for(int q = 0;q < x.size();q++) { for(int w = 0;w < x[0].size();w++) { name n; n.value = x[q][w]; n.i = q; n.j = w; s.push_back(n); } } std::sort(s.begin(),s.end()); int i = s.size() - 1; int t = 0; std::vector<std::vector<name>> upper(N); while(i >= 0 && t < k * N / 2) { name e = s[i--]; if(group[e.i] == k) continue; upper[e.i].push_back(e); group[e.i]++; t++; } i = 0; t = 0; std::vector<std::vector<name>> lower(N); while(t < k * N / 2) { name e = s[i++]; if(ans[e.i][e.j] != -1) continue; if(group[e.i] == k) continue; lower[e.i].push_back(e); group[e.i]++; t++; } std::vector<int> start_pos(N); int r = 0; int j = 0; while(true) { if (upper[j].size() == 0) { start_pos[j] = r; ++j; if(j == upper.size()) break; } if(upper[j].size() == 0) continue; round[r].push_back(upper[j].back().value); ans[upper[j].back().i][upper[j].back().j] = r; upper[j].pop_back(); ++r; r%=k; } r = 0; j = 0; while(j < lower.size()) { r = start_pos[j]; for(int q = 0;q < lower[j].size();q++) { round[r].push_back(lower[j].back().value); ans[lower[j].back().i][lower[j].back().j] = r; lower[j].pop_back(); ++r; r%+k; } ++j; } ll res = 0; for(int q = 0;q < k;q++) { std::sort(round[q].begin(),round[q].end()); for(int w = 0;w < N / 2;w++) { res -= round[q][w]; } for(int w = N / 2;w < N;w++) { res += round[q][w]; } } allocate_tickets(ans); return res; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int q = 0;q < x.size();q++) {
      |                ~~^~~~~~~~~~
tickets.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for(int w = 0;w < x[0].size();w++) {
      |                 ~~^~~~~~~~~~~~~
tickets.cpp:61:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<name> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |    if(j == upper.size()) break;
      |       ~~^~~~~~~~~~~~~~~
tickets.cpp:72:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<name> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |  while(j < lower.size()) {
      |        ~~^~~~~~~~~~~~~~
tickets.cpp:74:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<name>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for(int q = 0;q < lower[j].size();q++) {
      |                 ~~^~~~~~~~~~~~~~~~~
tickets.cpp:79:5: warning: statement has no effect [-Wunused-value]
   79 |    r%+k;
      |    ~^~~
tickets.cpp:18:6: warning: unused variable 'M' [-Wunused-variable]
   18 |  int M = x[0].size();
      |      ^
#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...