Submission #1013548

#TimeUsernameProblemLanguageResultExecution timeMemory
1013548Ausp3x카니발 티켓 (IOI20_tickets)C++17
16 / 100
398 ms121436 KiB
// 人外有人,天外有天 // author: Ausp3x #pragma GCC optimize("O1, O2, O3, Ofast, unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include "tickets.h" using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define pb push_back typedef long long lng; typedef pair<int, int> pi; typedef vector<int> vi; typedef pair<lng, lng> pl; typedef vector<lng, lng> vl; int const INF32 = 0x3f3f3f3f; lng const INF64 = 0x3f3f3f3f3f3f3f3f; lng find_maximum(int k, vector<vi> x) { int n = x.size(), m = x[0].size(); // val, idx vector<vector<pi>> sorted_x(n); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) sorted_x[i].push_back({x[i][j], i * m + j}); for (int i = 0; i < n; i++) sort(sorted_x[i].begin(), sorted_x[i].end()); lng S = 0; // val, idx vector<priority_queue<pi>> unused(n), minus(n); for (int i = 0; i < n; i++) { for (int j = k; j < m; j++) unused[i].push(sorted_x[i][j]); for (int j = 0; j < k; j++) { S -= sorted_x[i][j].fi; minus[i].push(sorted_x[i][j]); } } // sum, col priority_queue<pi> max_change; for (int i = 0; i < n; i++) max_change.push({unused[i].top().fi + minus[i].top().fi, i}); int cnt = 0; vector<pair<int, deque<pi>>> plus(n); while (!max_change.empty() && cnt < k * n / 2) { auto [sum, col] = max_change.top(); max_change.pop(); S += sum; pi unused_cur = unused[col].top(); unused[col].pop(); minus[col].pop(); plus[col].fi++; plus[col].se.push_back(unused_cur); if (unused[col].size() > 0 && minus[col].size() > 0) max_change.push({unused[col].top().fi + minus[col].top().fi, col}); cnt++; } for (int i = 0; i < n; i++) { plus[i].se.push_back(minus[i].top()); minus[i].pop(); } vector<vi> s(n, vi(m, -1)); for (int i = 0; i < k; i++) { sort(plus.begin(), plus.end(), greater<pair<int, deque<pi>>>()); for (int j = 0; j < n / 2; j++) { auto [val, idx] = plus[j].se.front(); plus[j].se.pop_front(); if (plus[j].fi > 0) plus[j].fi--; else S += 2 * val; s[idx / m][idx % m] = i; } for (int j = n / 2; j < n; j++) { auto [val, idx] = plus[j].se.back(); plus[j].se.pop_back(); s[idx / m][idx % m] = i; } } // for (int i = 0; i < n; i++) { // for (int j = 0; j < m; j++) // cout << s[i][j] << ' '; // cout << endl; // } allocate_tickets(s); return S; } /* int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; cin >> t; while (t--) { int n, m, k; cin >> n >> m >> k; vector<vector<int>> x(n, vector<int>(m)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> x[i][j]; cout << find_maximum(k, x) << endl; } return 0; } //*/

Compilation message (stderr)

tickets.cpp:4:55: warning: bad option '-f O2' to pragma 'optimize' [-Wpragmas]
    4 | #pragma GCC optimize("O1, O2, O3, Ofast, unroll-loops")
      |                                                       ^
tickets.cpp:4:55: warning: bad option '-f O3' to pragma 'optimize' [-Wpragmas]
tickets.cpp:4:55: warning: bad option '-f Ofast' to pragma 'optimize' [-Wpragmas]
tickets.cpp:4:55: warning: bad option '-f unroll-loops' to pragma 'optimize' [-Wpragmas]
In file included from tickets.cpp:7:
tickets.h:3:62: warning: bad option '-f O2' to attribute 'optimize' [-Wattributes]
    3 | long long find_maximum(int k, std::vector<std::vector<int>> d);
      |                                                              ^
tickets.h:3:62: warning: bad option '-f O3' to attribute 'optimize' [-Wattributes]
tickets.h:3:62: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
tickets.h:3:62: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
tickets.h:3:62: warning: bad option '-f O2' to attribute 'optimize' [-Wattributes]
tickets.h:3:62: warning: bad option '-f O3' to attribute 'optimize' [-Wattributes]
tickets.h:3:62: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
tickets.h:3:62: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
tickets.h:4:56: warning: bad option '-f O2' to attribute 'optimize' [-Wattributes]
    4 | void allocate_tickets( std::vector<std::vector<int>> _x);
      |                                                        ^
tickets.h:4:56: warning: bad option '-f O3' to attribute 'optimize' [-Wattributes]
tickets.h:4:56: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
tickets.h:4:56: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
tickets.h:4:56: warning: bad option '-f O2' to attribute 'optimize' [-Wattributes]
tickets.h:4:56: warning: bad option '-f O3' to attribute 'optimize' [-Wattributes]
tickets.h:4:56: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
tickets.h:4:56: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
tickets.cpp:23:37: warning: bad option '-f O2' to attribute 'optimize' [-Wattributes]
   23 | lng find_maximum(int k, vector<vi> x) {
      |                                     ^
tickets.cpp:23:37: warning: bad option '-f O3' to attribute 'optimize' [-Wattributes]
tickets.cpp:23:37: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
tickets.cpp:23:37: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
#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...