제출 #736896

#제출 시각아이디문제언어결과실행 시간메모리
736896sentheta카니발 티켓 (IOI20_tickets)C++17
100 / 100
689 ms97060 KiB
#include "tickets.h" // author : sentheta aka vanwij #include<iostream> #include<iomanip> #include<algorithm> #include<cassert> #include<random> #include<chrono> #include<cmath> #include<string> #include<vector> #include<bitset> #include<queue> #include<stack> #include<map> #include<set> using namespace std; #define Int long long #define V vector #define pii pair<Int,Int> #define ff first #define ss second mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define pow2(x) (1LL<<(x)) #define msb(x) (63-__builtin_clzll(x)) #define bitcnt(x) (__builtin_popcountll(x)) #define nl '\n' #define _ << ' ' << #define all(x) (x).begin(), (x).end() #define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++) #define dbg(x) if(1) cout << "?" << #x << " : " << (x) << endl << flush; const int N = 1505; Int n, m, k; V<V<int>> a; Int sum = 0; V<V<int>> ans; V<int> sneg[N], unused[N]; // count of pos for each color Int poscnt[N]; // pointer to next positive/negative Int posptr[N], negptr[N]; Int find_maximum(int _k,V<V<int>> _a){ a.swap(_a); n = a.size(); m = a[0].size(); k = _k; // {delta, color} priority_queue<pii> pq; rep(i,0,n){ posptr[i] = m-1; negptr[i] = 0; rep(j,0,k){ sneg[i].push_back(a[i][j]); sum -= a[i][j]; } unused[i] = a[i]; pq.push({0LL+unused[i].back()+sneg[i].back(), i}); } // change n*k/2 cards to pos rep(loop,0,n*k/2){ auto[delta,i] = pq.top(); pq.pop(); sneg[i].pop_back(); unused[i].pop_back(); sum += delta; poscnt[i]++; if(!sneg[i].empty()){ pq.push({unused[i].back()+sneg[i].back(), i}); } } // assign answer ans = V<V<int>>(n,V<int>(m,-1)); rep(t,0,k){ V<int> ord(n); rep(i,0,n) ord[i] = i; sort(all(ord),[&](int i,int j){ return poscnt[i] < poscnt[j]; }); // assign negative rep(ii,0,n/2){ int i = ord[ii]; ans[i][negptr[i]++] = t; } // assign positive rep(ii,n/2,n){ int i = ord[ii]; ans[i][posptr[i]--] = t; poscnt[i]--; } } allocate_tickets(ans); return sum; }
#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...