제출 #928143

#제출 시각아이디문제언어결과실행 시간메모리
928143EJIC_B_KEDAX카니발 티켓 (IOI20_tickets)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "tickets.h" using ll = long long; using namespace std; mt19937_64 mt(time(nullptr)); ll find_maximum(int k, vector<vector<int>> t) { int n = t.size(), m = t[0].size(); vector<int> all; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { all.push_back(t[i][j]); } } sort(all.begin(), all.end()); int middle = all[all.size() / 2]; ll res = 0; vector<pair<ll, int>> a(n); vector<int> bg(n, 0), end(n, m - 1); vector<vector<int>> s(n, vector<int>(m, -1)); for (int i = 0; i < n; i++) { a[i].first = 0; a[i].second = i; for (int j = 0; j < m; j++) { t[i][j] -= middle; } } int bgs = 0, ends = 0; for (int i = 0; i < n; i++) { for (int st = 0; st < k; st++) { if ((abs(t[i][bg[i]]) > abs(t[i][end[i]]) && t[i][bg[i]] <= 0) || t[i][end[i]] < 0) { bgs++; bg[i]++; } else { ends++; end[i]--; } } } if (bgs > ends) { multiset<pair<int, int>> st; for (int i = 0; i < n; i++) { for (int j = bg[i] - 1; j >= 0; j--) { int sw = end[i] - bg[i] - j - 1; if (t[i][sw] >= 0) { st.emplace(-t[i][j] - t[i][sw], i); } } } while (bgs > ends) { bgs--; ends++; auto [w, i] = *st.begin(); st.erase(st.begin()); bg[i]--; end[i]++; } } else { multiset<pair<int, int>> st; for (int i = 0; i < n; i++) { for (int j = end[i] + 1; j < m; j++) { int sw = bg[i] + j - end[i] - 1; if (t[i][sw] <= 0) { st.emplace(t[i][j] + t[i][sw], i); } } } while (bgs < ends) { bgs++; ends--; auto [w, i] = *st.begin(); st.erase(st.begin()); bg[i]++; end[i]--; } } vector<int> l(n), r(n); ll res = 0; for (int i = 0; i < n; i++) { l[i] = bg[i]; r[i] = m - end[i] - 1; for (int j = 0; j < l[i]; j++) { res -= t[i][j]; } for (int j = 0; j < r[i]; j++) { res += t[i][m - j - 1]; } } for (int st = 0; st < k; st++) { vector<int> used(n, 0); int bal = 0; for (int i = 0; i < n; i++) { if (l[i] == k - st) { used[i] = 1; l[i]--; s[i][l[i]] = st; bal--; } if (r[i] == k - st) { used[i] = 1; s[i][m - r[i]] = st; r[i]--; bal++; } } for (int i = 0; i < n; i++) { if (!used[i]) { if (bal > 0) { used[i] = 1; l[i]--; s[i][l[i]] = st; bal--; } else { used[i] = 1; s[i][m - r[i]] = st; r[i]--; bal++; } } } } allocate_tickets(s); return res; }

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

tickets.cpp: In function 'll find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:81:8: error: redeclaration of 'll res'
   81 |     ll res = 0;
      |        ^~~
tickets.cpp:20:8: note: 'll res' previously declared here
   20 |     ll res = 0;
      |        ^~~