Submission #87191

#TimeUsernameProblemLanguageResultExecution timeMemory
87191jasony123123Hokej (COCI17_hokej)C++11
120 / 120
463 ms25552 KiB
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/assoc_container.hpp> using namespace std; //using namespace __gnu_pbds; #define FOR(i,start,end) for(int i=start;i<(int)(end);i++) #define FORE(i,start,end) for(int i=start;i<=(int)end;i++) #define RFOR(i,start,end) for(int i = start; i>end; i--) #define RFORE(i,start,end) for(int i = start; i>=end; i--) #define vsort(a) sort(a.begin(), a.end()); #define mp make_pair #define v vector #define sf scanf #define pf printf typedef long long ll; typedef pair<int, int > pii; typedef pair<ll, ll> pll; //template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void io(); int M, N; pair<pii, int> players[500000]; // <quality, endurance>, idx int sched[6][500001]; ll score = 0; int curplayers[6]; void initSc() { int r = 0, c = 0; FOR(i, 0, N) { pii p = players[i].first; // <quality, endurance> int pidx = players[i].second; sched[r][c] = pidx; if (c + p.second < M) { score += (ll)p.first*p.second; c += p.second; } else if (c + p.second == M) { score += (ll)p.first*p.second; c = 0; r++; if (r >= 6) break; } else { // c+p.endu>M score += (ll)p.first*(M - c); p.second -= M - c; c = 0; r++; if (r >= 6) break; sched[r][c] = pidx; score += (ll)p.first*p.second; c += p.second; } } } int main() { // io(); cin >> M >> N; FOR(i, 0, N) { cin >> players[i].first.first >> players[i].first.second; players[i].second = i + 1; } sort(players, players + N, greater<pair<pii, int>>()); initSc(); cout << score << "\n"; FOR(i, 0, 6) { curplayers[i] = sched[i][0]; cout << curplayers[i] << " "; } cout << "\n"; v<pair<int, pii>> stuff; FOR(i, 1, M) { set<int> enter, exit; FOR(j, 0, 6) if (sched[j][i] != 0) { enter.insert(sched[j][i]); exit.insert(curplayers[j]); curplayers[j] = sched[j][i]; } v<int> erases; for (int x : enter) if (exit.find(x) != exit.end()) erases.push_back(x); for (int x : erases) enter.erase(x), exit.erase(x); assert(enter.size() == exit.size()); auto enterIt = enter.begin(); auto exitIt = exit.begin(); while (enterIt != enter.end() && exitIt != exit.end()) { stuff.push_back({ i,{*exitIt, *enterIt} }); enterIt++, exitIt++; } } cout << stuff.size() << "\n"; for (auto x : stuff) { cout << x.first << " " << x.second.first << " " << x.second.second << "\n"; } return 0; } void io() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #else // online submission #endif ios_base::sync_with_stdio(false); cin.tie(NULL); }

Compilation message (stderr)

hokej.cpp: In function 'void io()':
hokej.cpp:116:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("input.in", "r", stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
hokej.cpp:117:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("output.out", "w", stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...