Submission #1064915

# Submission time Handle Problem Language Result Execution time Memory
1064915 2024-08-18T19:20:31 Z ArthuroWich Carnival Tickets (IOI20_tickets) C++17
0 / 100
1 ms 600 KB
#include "tickets.h"
#include<bits/stdc++.h>
using namespace std;
long long find_maximum(int k, vector<vector<int>> x) {
    int n = x.size(), m = x[0].size();
    vector<vector<int>> answer(n, vector<int>(m, -1));
    vector<deque<pair<int, int>>> t(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            t[i].push_back({x[i][j], j});
        }
        sort(t[i].begin(), t[i].end());
    }
    int ans = 0;
    for (int c = 0; c < k; c++) {
        vector<int> arr, vis(n, 0);
        vector<tuple<int, int, int>> a;
        for (int i = 0; i < n; i++) {
            a.push_back({t[i].back().first, i, t[i].back().second});
            if (t[i].size() > 1) {
                a.push_back({t[i].front().first, i, t[i].front().second});
            }
        }
        sort(a.begin(), a.end());
        for (int ind = 0; ind < a.size(); ind++) {
            auto [v, i, j] = a[ind];
            if (arr.size() == n/2) {
                break;
            }
            if (vis[i]) {
                continue;
            }
            vis[i] = 1;
            if (t[i].back().second == j) {
                t[i].pop_back();
            } else {
                t[i].pop_front();
            }
            answer[i][j] = c;
            arr.push_back(v);
        }
        reverse(a.begin(), a.end());
        for (int ind = 0; ind < a.size(); ind++) {
            auto [v, i, j] = a[ind];
            if (vis[i]) {
                continue;
            }
            vis[i] = 1;
            if (t[i].back().second == j) {
                t[i].pop_back();
            } else {
                t[i].pop_front();
            }
            answer[i][j] = c;
            arr.push_back(v);
        }
        sort(arr.begin(), arr.end());
        int med = arr[n/2-1];
        for (int i = 0; i < n; i++) {
            ans += abs(arr[i]-med);
        }
    }
    allocate_tickets(answer);
    return ans;
}

Compilation message

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:25:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (int ind = 0; ind < a.size(); ind++) {
      |                           ~~~~^~~~~~~~~~
tickets.cpp:27:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |             if (arr.size() == n/2) {
      |                 ~~~~~~~~~~~^~~~~~
tickets.cpp:43:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for (int ind = 0; ind < a.size(); ind++) {
      |                           ~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Contestant returned 18919508441 but the tickets gives a total value of 1739639257
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Contestant returned 2307346107 but the tickets gives a total value of -1987621189
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Contestant returned 5 while correct return value is 6.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Contestant returned 11 while correct return value is 13.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Contestant returned 11 while correct return value is 13.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Contestant returned 11 while correct return value is 13.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Contestant returned 18919508441 but the tickets gives a total value of 1739639257
5 Halted 0 ms 0 KB -