Submission #305215

#TimeUsernameProblemLanguageResultExecution timeMemory
305215VimmerCarnival Tickets (IOI20_tickets)C++14
27 / 100
739 ms53880 KiB
#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++; while (pos[nm].S + 1 < m && pos[nm].S <= pos[nm].F) pos[nm].S++;} else {r[nm][pos[nm].S] = u; mk[nm][pos[nm].S++] = 1;} 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 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...