이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "tickets.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define N 1005
#define PB push_back
#define sz(x) int(x.size())
#define P 31
#define F first
#define M ll(1e9 + 7)
#define S second
#define all(x) x.begin(), x.end()
#define endl '\n'
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
//typedef tree<int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll mlt(ll a, ll b) {return (a * b) % M;}
ll sm(ll a, ll b) {return (a + b) % M;}
ll find_maximum(int k, vector<vector<int> > x)
{
int n = sz(x);
int m = sz(x[0]);
vector <vector <int> > r;
r.resize(n);
pair <int, int> pos[n];
for (int i = 0; i < n; i++)
{
pos[i] = {0, m - k};
r[i].resize(m, -1);
}
ll ans = 0, sum = 0;
set <pair <int, int> > se; se.clear();
bool mk[n][m];
memset(mk, 0, sizeof(mk));
for (int i = 0; i < n; i++)
{sum += x[i][m - k]; se.insert({x[i][0] + x[i][m - k], i});}
for (int u = 0; u < k; u++)
{
set <pair <int, int> > st = se;
se.clear();
int i = 0;
ll snt = 0;
while (sz(st) > 0)
{
int nm = (*st.begin()).S;
if (i < n / 2) sum -= (*st.begin()).F;
st.erase(st.begin());
if (i < n / 2)
{r[nm][pos[nm].F] = u; mk[nm][pos[nm].F] = 1; while (mk[nm][pos[nm].F]) pos[nm].F++; if (pos[nm].S <= pos[nm].F) pos[nm].S++;}
else {r[nm][pos[nm].S] = u; mk[nm][pos[nm].S++] = 1; while (mk[nm][pos[nm].F]) pos[nm].F++;}
if (u + 1 != k) {snt += x[nm][pos[nm].S]; se.insert({x[nm][pos[nm].F] + x[nm][pos[nm].S], nm});}
i++;
}
ans += sum;
sum = snt;
}
allocate_tickets(r);
return ans;
}
//int main()
//{
// cout << find_maximum(3, {{0, 1, 1, 1}, {0, 1, 1, 1}, {0, 1, 1, 1}, {0, 0, 0, 1}}) << endl;
//}
# | 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... |