제출 #434637

#제출 시각아이디문제언어결과실행 시간메모리
434637yuto1115카니발 티켓 (IOI20_tickets)C++17
25 / 100
941 ms61120 KiB
#include "tickets.h"
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); i++)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; i--)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll find_maximum(int k, vvi x) {
    int n = x.size();
    int m = x[0].size();
    ll ans = 0;
    // 0 -> minus, 1 -> plus
    vvi alloc(n, vi(m, -1));
    if (k == m) {
        vp ls;
        rep(i, n) rep(j, m) ls.eb(x[i][j], i * m + j);
        sort(all(ls));
        rep(i, n * m / 2) {
            ans -= ls[i].first;
            int cl = ls[i].second / m;
            int num = ls[i].second % m;
            alloc[cl][num] = 0;
        }
        rep2(i, n * m / 2, n * m) {
            ans += ls[i].first;
            int cl = ls[i].second / m;
            int num = ls[i].second % m;
            alloc[cl][num] = 1;
        }
    } else {
        assert(false);
    }
//    rep(i,n) rep(j,m) cerr << alloc[i][j] << (j == m-1 ? '\n' : ' ');
//    cerr << endl;
    auto proc = [&](int &i) {
        int pi = i;
        i = (i < k - 1 ? i + 1 : 0);
        return pi;
    };
    int now = 0;
    rep(i, n) {
        int it = now;
        rep(j, m) {
            if (alloc[i][j] == -1) continue;
            if (alloc[i][j] == 0) proc(now);
            alloc[i][j] = proc(it);
        }
    }
    assert(now == 0);
    allocate_tickets(alloc);
    return ans;
}
#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...