Submission #1057065

#TimeUsernameProblemLanguageResultExecution timeMemory
1057065RecursiveCoCarnival Tickets (IOI20_tickets)C++17
100 / 100
389 ms54356 KiB
// CF template, version 3.0 #include <bits/stdc++.h> #include "tickets.h" using namespace std; #define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0) #define getTest int t; cin >> t #define eachTest for (int _var=0;_var<t;_var++) #define get(name) int (name); cin >> (name) #define out(o) cout << (o) #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); } #define sortl(name) sort((name).begin(), (name).end()) #define rev(name) reverse((name).begin(), (name).end()) #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++) #define decision(b) if (b){out("YES");}else{out("NO");} //#define int long long int template <typename T, typename I> struct segtree { int n; vector<T> tree; vector<I> initial; T id; segtree(int i_n, vector<I> i_initial, T i_id): n(i_n), initial(i_initial), id(i_id) { tree.resize(4 * n); } T conquer(T left, T right) { // write your conquer function } T value(I inp) { // write your value function } void build(int v, int l, int r) { if (l == r) tree[v] = value(initial[l]); else { int middle = (l + r) / 2; build(2 * v, l, middle); build(2 * v + 1, middle + 1, r); tree[v] = conquer(tree[2 * v], tree[2 * v + 1]); } } void upd(int v, int l, int r, int i, I x) { if (l == r) tree[v] = value(x); else { int middle = (l + r) / 2; if (middle >= i) upd(2 * v, l, middle, i, x); else upd(2 * v + 1, middle + 1, r, i, x); tree[v] = conquer(tree[2 * v], tree[2 * v + 1]); } } T query(int v, int l, int r, int ql, int qr) { if (ql <= l && r <= qr) return tree[v]; else if (r < ql || qr < l) return id; int middle = (l + r) / 2; T left = query(2 * v, l, middle, ql, qr); T right = query(2 * v + 1, middle + 1, r, ql, qr); return conquer(left, right); } }; // vector<int> long long find_maximum(int k, vector<vector<int>> X) { int N = X.size(); int M = X[0].size(); long long ans = 0; forto(N / 2, i) forto(k, j) ans += (long long) X[i][M - j - 1]; forto(N / 2, i) forto(k, j) ans -= (long long) X[N / 2 + i][j]; vector<int> ind(N, 0); forto(N / 2, i) ind[i] = k; priority_queue<pair<long long, int>> pq1; forto(N / 2, i) pq1.push({(long long) (-X[i][M - k]) + (long long) (-X[i][0]), i}); priority_queue<pair<long long, int>> pq2; forto(N / 2, i) pq2.push({(long long) (X[N / 2 + i][M - 1]) + (long long) (X[N / 2 + i][k - 1]), N / 2 + i}); while (!pq1.empty() && !pq2.empty() && pq1.top().first + pq2.top().first > 0) { auto top1 = pq1.top(); auto top2 = pq2.top(); pq1.pop(); pq2.pop(); ans += top1.first + top2.first; int index1 = --ind[top1.second]; if (index1 > 0) { pq1.push({(long long) (-X[top1.second][M - index1]) + (long long) (-X[top1.second][k - index1]), top1.second}); } int index2 = ++ind[top2.second]; if (index2 < k) { pq2.push({(long long) (X[top2.second][M - index2 - 1]) + (long long) (X[top2.second][k - index2 - 1]), top2.second}); } } vector<vector<int>> which(N, vector<int>(M, -1)); vector<int> pref(N, 0); vector<int> suf(N, 0); forto(N, i) suf[i] = ind[i], pref[i] = k - ind[i]; vector<int> inc(N, 0); vector<int> dec(N, 0); int iter = 0; while (k) { int suffixes = 0; int prefixes = 0; vector<bool> already(N, false); forto(N, i) { if (suf[i] == k) { which[i][M - (++dec[i])] = iter; suffixes++; suf[i]--; already[i] = true; } else if (pref[i] == k) { which[i][inc[i]++] = iter; prefixes++; pref[i]--; already[i] = true; } } forto(N, i) { if (already[i]) continue; if (suf[i] && suffixes < N / 2) { which[i][M - (++dec[i])] = iter; suffixes++; suf[i]--; } else { which[i][inc[i]++] = iter; prefixes++; pref[i]--; } } k--; iter++; } allocate_tickets(which); return ans; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
tickets.cpp:76:5: note: in expansion of macro 'forto'
   76 |     forto(N / 2, i) forto(k, j) ans += (long long) X[i][M - j - 1];
      |     ^~~~~
tickets.cpp:16:35: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
tickets.cpp:76:21: note: in expansion of macro 'forto'
   76 |     forto(N / 2, i) forto(k, j) ans += (long long) X[i][M - j - 1];
      |                     ^~~~~
tickets.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
tickets.cpp:77:5: note: in expansion of macro 'forto'
   77 |     forto(N / 2, i) forto(k, j) ans -= (long long) X[N / 2 + i][j];
      |     ^~~~~
tickets.cpp:16:35: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
tickets.cpp:77:21: note: in expansion of macro 'forto'
   77 |     forto(N / 2, i) forto(k, j) ans -= (long long) X[N / 2 + i][j];
      |                     ^~~~~
tickets.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
tickets.cpp:79:5: note: in expansion of macro 'forto'
   79 |     forto(N / 2, i) ind[i] = k;
      |     ^~~~~
tickets.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
tickets.cpp:81:5: note: in expansion of macro 'forto'
   81 |     forto(N / 2, i) pq1.push({(long long) (-X[i][M - k]) + (long long) (-X[i][0]), i});
      |     ^~~~~
tickets.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
tickets.cpp:83:5: note: in expansion of macro 'forto'
   83 |     forto(N / 2, i) pq2.push({(long long) (X[N / 2 + i][M - 1]) + (long long) (X[N / 2 + i][k - 1]), N / 2 + i});
      |     ^~~~~
tickets.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
tickets.cpp:102:5: note: in expansion of macro 'forto'
  102 |     forto(N, i) suf[i] = ind[i], pref[i] = k - ind[i];
      |     ^~~~~
tickets.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
tickets.cpp:110:9: note: in expansion of macro 'forto'
  110 |         forto(N, i) {
      |         ^~~~~
tickets.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
tickets.cpp:123:9: note: in expansion of macro 'forto'
  123 |         forto(N, i) {
      |         ^~~~~
#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...