Submission #922768

# Submission time Handle Problem Language Result Execution time Memory
922768 2024-02-06T06:10:38 Z Alihan_8 Carnival Tickets (IOI20_tickets) C++17
27 / 100
404 ms 51720 KB
#include <bits/stdc++.h>

#include "tickets.h"

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

long long find_maximum(int k, std::vector<std::vector<int>> a) {
    int n = a.size(), m = a[0].size();

	vector <int> L(n), R(n, m - 1);

	vector <vector<int>> ret(n, vector <int> (m, -1));

	for ( int t = 0; t < k; t++ ){

        vector <ar<int,2>> p;

        for ( int j = 0; j < n; j++ ){
            p.pb({a[j][L[j]] + a[j][R[j]], j});
        }

        sort(all(p));

        for ( int i = 0; i < n; i++ ){
            int j = p[i][1];
            if ( i < n / 2 ){
                ret[j][L[j]] = t;
                L[j]++;
            } else{
                ret[j][R[j]] = t;
                R[j]--;
            }
        }
	}

	allocate_tickets(ret);

	auto f = [&](auto a){
        sort(all(a));
        int s = a.size();
        i64 cnt = 0;
        for ( auto &x: a ){
            cnt += abs(a[s / 2] - x);
        }
        return cnt;
	};

    vector <vector<int>> q(k);

    for ( int i = 0; i < n; i++ ){
        for ( int j = 0; j < m; j++ ){
            if ( ret[i][j] != -1 ){
                q[ret[i][j]].pb(a[i][j]);
            }
        }
    }

    i64 ans = 0;
    for ( auto &x: q ){
        ans += f(x);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 604 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 348 KB Output is correct
5 Correct 18 ms 2392 KB Output is correct
6 Correct 404 ms 51720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 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 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 348 KB Contestant returned 11 while correct return value is 13.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 604 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 348 KB Output is correct
11 Correct 18 ms 2392 KB Output is correct
12 Correct 404 ms 51720 KB Output is correct
13 Incorrect 0 ms 344 KB Contestant returned 5 while correct return value is 6.
14 Halted 0 ms 0 KB -