This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#include"tickets.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
template <class T>
void rd(T &x) {
int sgn = 1;
char ch;
x = 0;
for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
if (ch == '-') ch = getchar(), sgn = -1;
for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
x *= sgn;
}
template <class T>
void wr(T x) {
if (x < 0) putchar('-'), wr(-x);
else if (x < 10) putchar(x + '0');
else wr(x / 10), putchar(x % 10 + '0');
}
void usaco(string s){
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
ll find_maximum(int k, std::vector<std::vector<int> > x) {
const int n = x.size(), m = x[0].size();
vector<pair<ll, int>> pairs;
vector<int> cur0(n), cur1(n, m), rank(n), cnt0(n), cnt1(n);
ll answer = 0;
pairs.reserve(n * k);
for(int i = 0; i < n; ++i) {
for(int j = 1; j <= k; ++j) {
pairs.emplace_back(x[i][k - j] + x[i][m - j], i);
answer -= x[i][j - 1];
}
}
nth_element(pairs.rbegin(), pairs.rbegin() + n / 2 * k, pairs.rend());
for(int i = 0; i < n / 2 * k; ++i) ++ cnt1[pairs[i].second], answer += pairs[i].first;
for(int i = 0; i < n; ++i) cnt0[i] = k - cnt1[i], rank[i] = i;
for(int i = 0; i < n; ++i) fill(x[i].begin(), x[i].end(), -1);
const auto cmp = [&](int x, int y) { return cnt0[x] < cnt0[y]; };
for(int R = 0; R < k; ++R) {
nth_element(rank.begin(), rank.begin() + n / 2, rank.end(), cmp);
for(int i = 0;i < n / 2;++i) x[rank[i]][--cur1[rank[i]]] = R, --cnt1[rank[i]];
for(int i = n / 2;i < n;++i) x[rank[i]][cur0[rank[i]]++] = R, --cnt0[rank[i]];
}
allocate_tickets(x);
return answer;
}
Compilation message (stderr)
tickets.cpp: In function 'void usaco(std::string)':
tickets.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
31 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tickets.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
32 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |