답안 #928126

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
928126 2024-02-15T21:05:42 Z EJIC_B_KEDAX 카니발 티켓 (IOI20_tickets) C++17
41 / 100
1117 ms 55024 KB
#include <bits/stdc++.h>
#include "tickets.h"

using ll = long long;

using namespace std;

mt19937_64 mt(time(nullptr));

ll find_maximum(int k, vector<vector<int>> t) {
    int n = t.size(), m = t[0].size();
    vector<int> all;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            all.push_back(t[i][j]);
        }
    }
    sort(all.begin(), all.end());
    int middle = all[all.size() / 2];
    ll res = 0;
    vector<pair<ll, int>> a(n);
    vector<int> bg(n, 0), end(n, m - 1);
    vector<vector<int>> s(n, vector<int>(m, -1));
    for (int i = 0; i < n; i++) {
        a[i].first = 0;
        a[i].second = i;
        for (int j = 0; j < m; j++) {
            t[i][j] -= middle;
        }
    }
    for (int st = 0; st < k; st++) {
        vector<pair<int, int>> l, r;
        for (int i = 0; i < n; i++) {
            if ((abs(t[i][bg[i]]) > abs(t[i][end[i]]) && t[i][bg[i]] <= 0) || t[i][end[i]] < 0 || (t[i][end[i]] == 0 && mt() % 2)) {
                if (t[i][end[i]] < 0) {
                    l.emplace_back(INT32_MAX, i);
                } else if (!t[i][end[i]]) {
                    l.emplace_back(INT32_MAX / 2, i);
                } else {
                    l.emplace_back(abs(abs(t[i][bg[i]]) - abs(t[i][end[i]])), i);
                }
            } else {
                if (t[i][bg[i]] > 0) {
                    r.emplace_back(INT32_MAX, i);
                } else if (!t[i][bg[i]]) {
                    r.emplace_back(INT32_MAX / 2, i);
                } else {
                    r.emplace_back(abs(abs(t[i][bg[i]]) - abs(t[i][end[i]])), i);
                }
            }
        }
        sort(l.begin(), l.end(), greater<>());
        sort(r.begin(), r.end(), greater<>());
        set<int> li, ri;
        for  (auto [w, i] : l) {
            li.insert(i);
        }
        for  (auto [w, i] : r) {
            ri.insert(i);
        }
        while (l.size() > n / 2) {
            li.erase(l.back().second);
            ri.insert(l.back().second);
            l.pop_back();
        }
        while (r.size() > n / 2) {
            ri.erase(r.back().second);
            li.insert(r.back().second);
            r.pop_back();
        }
        vector<int> nw;
        for (int i : li) {
            s[i][bg[i]] = st;
            nw.push_back(t[i][bg[i]++]);
        }
        for (int i : ri) {
            s[i][end[i]] = st;
            nw.push_back(t[i][end[i]--]);
        }
        sort(nw.begin(), nw.end());
        for (int i : nw) {
            res += abs(i);
        }
        assert(0 >= nw[n / 2 - 1] && 0 <= nw[n / 2]);
    }
    allocate_tickets(s);
    return res;
}

Compilation message

tickets.cpp: In function 'll find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:61:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   61 |         while (l.size() > n / 2) {
      |                ~~~~~~~~~^~~~~~~
tickets.cpp:66:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |         while (r.size() > n / 2) {
      |                ~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 19 ms 2520 KB Output is correct
6 Correct 498 ms 54528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Contestant returned 5 while correct return value is 6.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 3 ms 556 KB Output is correct
5 Correct 38 ms 2508 KB Output is correct
6 Correct 6 ms 600 KB Output is correct
7 Correct 7 ms 856 KB Output is correct
8 Correct 1024 ms 54220 KB Output is correct
9 Correct 1053 ms 50860 KB Output is correct
10 Correct 1043 ms 52152 KB Output is correct
11 Correct 1117 ms 55024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 1 ms 348 KB Contestant returned 160988334890 while correct return value is 160993200494.
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 1 ms 348 KB Contestant returned 160988334890 while correct return value is 160993200494.
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 888 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 19 ms 2520 KB Output is correct
12 Correct 498 ms 54528 KB Output is correct
13 Incorrect 0 ms 348 KB Contestant returned 5 while correct return value is 6.
14 Halted 0 ms 0 KB -