Submission #1050321

# Submission time Handle Problem Language Result Execution time Memory
1050321 2024-08-09T08:44:27 Z dozer Carnival Tickets (IOI20_tickets) C++14
27 / 100
277 ms 60208 KB
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define sp " "
#define endl "\n"
#define LL node * 2
#define RR node * 2 + 1
#define ll long long
#define N 200005

const int modulo = 1e9 + 7;
const ll INF = 2e18 + 7;



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>> answer(n, vector<int>(m, -1));
    vector<vector<int>> done(n, vector<int>(m, 0));
    long long ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < k; j++) {
            ans -= x[i][j];
            done[i][j] = 1;
        }
    }

    vector<array<int, 3>> v;
    for (int i = 0; i < n; i++){
        for (int j = 1; j <= k; j++){
            int curr = m - j;
            int bk = k - j;
            v.pb({x[i][curr] + x[i][bk], i, curr});
        }
    }

    sort(v.rbegin(), v.rend());
    for (int i = 0; i < n * k / 2; i++){
        array<int, 3> curr = v[i];
        ans += curr[0];
        int bk = k - (m - curr[2]);
        done[curr[1]][bk] = 0;
        done[curr[1]][curr[2]] = 2;
    }

    vector<int> fpos(n, 0), bpos(n, m - 1);
    vector<int> fcnt(n, 0);
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (done[i][j] == 1) fcnt[i]++;
        }
    }

    for (int i = 0; i < k; i++){
        vector<int> todo(n, 0);
        iota(todo.begin(), todo.end(), 0);
        sort(todo.begin(), todo.end(), [&](int a, int b){
            return fcnt[a] > fcnt[b];
        });

        for (int j = 0; j < n / 2; j++){
            int curr = todo[j];
            answer[curr][fpos[curr]] = i;
            fpos[curr]++;
            fcnt[curr]--;
        }
        for (int j = n / 2; j < n; j++){
            int curr = todo[j];
            answer[curr][bpos[curr]] = i;
            bpos[curr]++;
        }
    }
    allocate_tickets(answer);
    return ans;
}
/*
static int n;
static int m;
static int k;
static std::vector<std::vector<int>> d;
static std::vector<std::vector<int>> x;
static int called = 0;

static void check(bool cond, std::string message) {
    if (!cond) {
        printf("%s\n", message.c_str());
        exit(0);
    }
}


void allocate_tickets( std::vector<std::vector<int>> _d) {
    check(!called, "allocate_tickets called more than once");
    d = _d;
    check((int)d.size() == n, "allocate_tickets called with parameter of wrong size");
    for (int i = 0; i < n; i++) {
        check((int)d[i].size() == m, "allocate_tickets called with parameter of wrong size");
    }
    called = 1;
}

int main() {
    fileio();
    assert(scanf("%d %d %d", &n, &m, &k) == 3);
    x.resize(n);
    for (int i = 0; i < n; i++) {
        x[i].resize(m);
        for (int j=0; j < m; j++) {
            assert(scanf("%d", &x[i][j]) == 1);
        }
    }
    fclose(stdin);

    long long answer = find_maximum(k, x);
    check(called, "failure to call allocate_tickets");
    printf("%lld\n", answer);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (j) printf(" ");
            printf("%d", d[i][j]);
        }
        printf("\n");
    }
    fclose(stdout);
    return 0;
}
*/
# 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 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
# 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 Correct 1 ms 604 KB Output is correct
5 Correct 11 ms 2652 KB Output is correct
6 Correct 277 ms 60208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB There is no ticket of color 0 on day 2
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB There is no ticket of color 1 on day 3
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB There is no ticket of color 1 on day 3
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB There is no ticket of color 1 on day 3
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 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 11 ms 2652 KB Output is correct
12 Correct 277 ms 60208 KB Output is correct
13 Incorrect 0 ms 344 KB There is no ticket of color 0 on day 2
14 Halted 0 ms 0 KB -