Submission #1012639

#TimeUsernameProblemLanguageResultExecution timeMemory
1012639ProtonDecay314카니발 티켓 (IOI20_tickets)C++17
11 / 100
1 ms860 KiB
/*

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<bool> vb;
#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define L(varll, mn, mx) for(ll varll = (mn); varll < (mx); varll++)
#define LR(varll, mx, mn) for(ll varll = (mx); varll > (mn); varll--)
#define LI(vari, mn, mx) for(int vari = (mn); vari < (mx); vari++)
#define LIR(vari, mx, mn) for(int vari = (mx); vari > (mn); vari--)
#define INPV(varvec) for(auto& varveci : (varvec)) cin >> varveci
#define fi first
#define se second
#define pb push_back
#define INF(type) numeric_limits<type>::max()
#define NINF(type) numeric_limits<type>::min()
#define TCASES int t; cin >> t; while(t--)

#ifndef DEBUG
#include "tickets.h"
#endif

#ifdef DEBUG
vvi ta;
void allocate_tickets(const vvi& a_ta) {
    LI(i, 0, (int)ta.size()) {

        copy(a_ta[i].begin(), a_ta[i].end(), back_inserter(ta[i]));
    }
}
#endif

ll find_maximum(int k, vvi x) {
    int n = x.size(), m = x[0].size();
    vvi talloc;
    LI(i, 0, n) {
        vi tallocr(m, -1);
        talloc.pb(tallocr);
    }

    ll ans = 0ll;

    // Subtask 1
    if(m == 1) {
        vi vals;
        LI(i, 0, n) {
            vals.pb(x[i][0]);
        }

        sort(vals.begin(), vals.end());
        LI(i, 0, n >> 1) {
            ans -= (ll)vals[i];
        }

        LI(i, n >> 1, n) {
            ans += (ll)vals[i];
        }

        LI(i, 0, n) {
            talloc[i][0] = 0;
        }
    } else if(k == 1) {
        // Include everything!!

        vpll oppcosts; // wow, thanks Ma'am Bambie, I really love economics
        vpll color_extrema;

        LI(i, 0, n) {
            color_extrema.pb({((ll)accumulate(x[i].begin(), x[i].end(), NINF(ll), [](ll a, ll b) {return max(a, b);})), ((ll)accumulate(x[i].begin(), x[i].end(), INF(ll), [](ll a, ll b) {return min(a, b);}))});
            oppcosts.pb({color_extrema[i].fi - color_extrema[i].se, i});
        }

        sort(oppcosts.begin(), oppcosts.end());
        
        LI(i, 0, n >> 1) {
            int cur_ind = oppcosts[i].se;
            int cur_val = color_extrema[cur_ind].se;
            ans -= cur_val;
            talloc[cur_ind][distance(x[cur_ind].begin(), find(x[cur_ind].begin(), x[cur_ind].end(), cur_val))] = 0;
        }

        LI(i, n >> 1, n) {
            int cur_ind = oppcosts[i].se;
            int cur_val = color_extrema[oppcosts[i].se].fi;
            ans += cur_val;
            talloc[cur_ind][distance(x[cur_ind].begin(), find(x[cur_ind].begin(), x[cur_ind].end(), cur_val))] = 0;
        }
    }

    allocate_tickets(talloc);

    return ans;
}

#ifdef DEBUG
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    
    vvi x;

    LI(i, 0, n) {
        vi xr(m, 0);
        vi tar;
        INPV(xr);
        x.pb(xr);
        ta.pb(tar);
    }

    cout << find_maximum(k, x) << "\n";

    LI(i, 0, n) {
        LI(j, 0, m) cout << ta[i][j] << " ";
        cout << "\n";
    }

    return 0;
}
#endif
#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...