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 "tickets.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
ll n, k, m;
vector<ll>mns, mxs, mns_, mxs_;
ll dp[1507][1507];
ll find_answer(vector<ll>a) {
ll ans = INF;
for (int i = 0; i < a.size(); i++) {
ll cur = 0;
for (int j = 0; j < a.size(); j++) {
cur += abs(a[i] - a[j]);
}
ans = min(ans, cur);
}
return ans;
}
ll find_maximum(int k, vector<vector<int>> x) {
n = x.size();
m = x[0].size();
if (m == 1) {
vector<vector<int>>ans;
vector<ll>v;
ans.resize(n);
for (int i = 0; i < n; i++) {
ans[i].resize(1, 0);
v.push_back(x[i][0]);
}
allocate_tickets(ans);
return find_answer(v);
}
if (k == 1) {
mns.push_back(0);
mxs.push_back(0);
for (int i = 0; i < n; i++) {
ll mn = INF, mx = 0;
int mn_ = -1, mx_ = -1;
for (int j = 0; j < m; j++) {
if (x[i][j] < mn) {
mn_ = j;
}
if (x[i][j] > mx) {
mx_ = j;
}
mn = min(mn, x[i][j] * 1ll);
mx = max(mx, x[i][j] * 1ll);
}
mns.push_back(mn);
mxs.push_back(mx);
mns_.push_back(mn_);
mxs_.push_back(mx_);
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j != 0 && j != i) {
dp[i][j] = max(dp[i - 1][j] + mxs[i], dp[i - 1][j - 1] - mns[i]);
}
else if (j == 0) {
dp[i][j] = dp[i - 1][j] + mxs[i];
}
else {
dp[i][j] = dp[i - 1][j - 1] - mns[i];
}
}
}
string s = "";
int j = n / 2;
for (int i = n; i > 0; i--) {
if (j == i || (j != 0 && dp[i - 1][j - 1] - mns[i] == dp[i][j])) {
s += '0';
j--;
}
else {
s += '1';
}
}
reverse(s.begin(), s.end());
vector<vector<int>>ans;
ans.resize(n);
for (int i = 0; i < n; i++) {
ans[i].resize(m, -1);
}
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
ans[i][mns_[i]] = 0;
}
else {
ans[i][mxs_[i]] = 0;
}
}
allocate_tickets(ans);
return dp[n][n / 2];
}
}
/*
3 1 1 1 2 3
*/
Compilation message (stderr)
tickets.cpp: In function 'll find_answer(std::vector<long long int>)':
tickets.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
tickets.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (int j = 0; j < a.size(); j++) {
| ~~^~~~~~~~~~
tickets.cpp: In function 'll find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:110:1: warning: control reaches end of non-void function [-Wreturn-type]
110 | }
| ^
# | 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... |