제출 #303077

#제출 시각아이디문제언어결과실행 시간메모리
303077tutis카니발 티켓 (IOI20_tickets)C++17
100 / 100
1156 ms75480 KiB
#include "tickets.h" #include <vector> #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); bool vien = true; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (x[i][j] < 0 || x[i][j] > 1) vien = false; vector<vector<int>> answer(n, vector<int>(m, -1)); int mxp = n / 2 * k; int M[n], P[n]; if (vien) { for (int i = 0; i < n; i++) { P[i] = 0; while (P[i] < m && x[i][m - 1 - P[i]] == 1) P[i]++; } for (int i = 0; i < n; i++) M[i] = k - P[i]; } else if (k < m) { long long del[n][k + 1]; for (int i = 0; i < n; i++) { long long d = 0; for (int c = 0; c < k; c++) d -= x[i][c]; for (int p = 0; p <= k; p++) { del[i][p] = d; d += x[i][k - 1 - p]; d += x[i][m - 1 - p]; } } vector<pair<int, int>>A; for (int i = 0; i < n; i++) { M[i] = P[i] = 0; for (int j = 0; j < k; j++) A.push_back({del[i][j + 1] - del[i][j], i}); } sort(A.begin(), A.end()); for (int i = 0; i < (int)A.size() / 2; i++) { M[A[i].second]++; } for (int i = (int)A.size() / 2; i < (int)A.size(); i++) { P[A[i].second]++; } } else { vector<pair<int, int>>A; for (int i = 0; i < n; i++) { M[i] = P[i] = 0; for (int j = 0; j < m; j++) A.push_back({x[i][j], i}); } sort(A.begin(), A.end()); for (int i = 0; i < (int)A.size() / 2; i++) { M[A[i].second]++; } for (int i = (int)A.size() / 2; i < (int)A.size(); i++) { P[A[i].second]++; } } int a[n]; int b[n]; for (int i = 0; i < n; i++) { a[i] = 0; b[i] = m - 1; } long long ret = 0; for (int g = 0; g < k; g++) { pair<int, int>xx[n]; for (int i = 0; i < n; i++) xx[i] = {P[i], i}; sort(xx, xx + n); for (int i = 0; i < n / 2; i++) { int id = xx[i].second; ret -= x[id][a[id]]; answer[id][a[id]] = g; a[id]++; M[id]--; } for (int i = n / 2; i < n; i++) { int id = xx[i].second; ret += x[id][b[id]]; answer[id][b[id]] = g; b[id]--; P[id]--; } } allocate_tickets(answer); return ret; }

컴파일 시 표준 에러 (stderr) 메시지

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:14:6: warning: unused variable 'mxp' [-Wunused-variable]
   14 |  int mxp = n / 2 * k;
      |      ^~~
#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...