Submission #722140

#TimeUsernameProblemLanguageResultExecution timeMemory
722140danikoynovCarnival Tickets (IOI20_tickets)C++14
100 / 100
811 ms98216 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1510; int N, M, K, used[maxn][maxn], vis[maxn]; ll dp[310][310 * 310]; vector < vector < int > > answer; vector < int > free_box[maxn]; struct element { ll delta, row; bool operator < (const element &e) const { return delta > e.delta; } }; struct box { int row, col; ll val; bool operator < (const box &bx) const { return val < bx.val; } }; bool cmp_box(box b1, box b2) { return b1.row < b2.row; } int pt[maxn], type[maxn][maxn]; long long find_maximum(int k, vector < vector < int > > x) { N = x.size(); M = x[0].size(); K = k; ll max_val = 0; for (int i = 0; i < N; i ++) for (int j = 0; j < M; j ++) max_val = max(max_val, (ll)(x[i][j])); answer.resize(N); for (int i = 0; i < N; i++) { answer[i].resize(M, - 1); } ll max_prize = 0; priority_queue < element > pq; for (int i = 0; i < N; i ++) { pt[i] = 0; for (int j = M - 1; j >= M - k; j --) { max_prize += x[i][j]; type[i][j] = 1; } element cur; cur.row = i; cur.delta = x[i][M - k] + x[i][0]; pq.push(cur); } for (int step = 0; step < N * k / 2; step ++) { element cur = pq.top(); pq.pop(); max_prize -= cur.delta; type[cur.row][M - k + pt[cur.row]] = 0; type[cur.row][pt[cur.row]] = -1; pt[cur.row] ++; if (pt[cur.row] < k) { cur.delta = x[cur.row][M - k + pt[cur.row]] + x[cur.row][pt[cur.row]]; pq.push(cur); } } vector < box > small, big; for (int i = 0; i < N; i ++) for (int j = 0; j < M; j ++) { if (type[i][j] == 0) continue; box b; b.row = i; b.col = j; b.val = x[i][j]; ///cout << i << " " << j << endl; if (type[i][j] == -1) small.push_back(b); else big.push_back(b); } sort(small.begin(), small.end(), cmp_box); sort(big.begin(), big.end(), cmp_box); int turn = 0; for (int i = 0; i < small.size(); i ++) { box b = small[i]; answer[b.row][b.col] = turn ++; if (turn == k) turn = 0; } for (int i = 0; i < N; i ++) { for (int j = 0; j < M; j ++) { if (answer[i][j] == -1) continue; vis[answer[i][j]] = 1; } for (int j = 0; j < k; j ++) { if (!vis[j]) free_box[i].push_back(j); vis[j] = 0; } } for (int i = 0; i < big.size(); i ++) { box b = big[i]; answer[b.row][b.col] = free_box[b.row].back(); free_box[b.row].pop_back(); } allocate_tickets(answer); return max_prize; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:109:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<box>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |         for (int i = 0; i < small.size(); i ++)
      |                         ~~^~~~~~~~~~~~~~
tickets.cpp:133:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<box>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |         for (int i = 0; i < big.size(); 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...