제출 #432139

#제출 시각아이디문제언어결과실행 시간메모리
432139peuch카니발 티켓 (IOI20_tickets)C++17
27 / 100
707 ms105860 KiB
#include "tickets.h" #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(); vector<vector<pair<long long, int> > > ord (n, vector<pair<long long, int> > (m)); vector<deque<pair<int, int> > > pilha (n); vector<vector<int> > ans (n, vector<int> (m, -1)); int maxi = 0; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++) ord[i][j] = make_pair(x[i][j], j), maxi = max(maxi, x[i][j]); sort(ord[i].begin(), ord[i].end()); for(int j = 0; j < m; j++) pilha[i].push_back(ord[i][j]); } if(maxi == 1){ long long sum = 0; long long ones = 0; long long zeros = 0; for(int i = 0; i < n; i++){ long long cnt = 0; for(int j = 0; j < m; j++) cnt += x[i][j]; if(cnt > m / 2){ long long aux = m - cnt; sum += min(2 * aux, (long long)k); if(2 * aux >= k) continue; ones += k - 2 * aux; } else{ int aux = m - cnt; sum += min(2 * cnt, (long long)k); if(2 * cnt >= k) continue; zeros += k - 2 * cnt; } } sum += 2 * min(zeros, ones); vector<int> coringa, zero, um; for(int i = 0; i < n; i++){ coringa.push_back(i); } for(int i = 0; i < k; i++){ int zeros = 0; int ones = 0; vector<int> marc(n, 0); for(int j = 0; j < n; j++){ if(pilha[j].back().first == 0){ ans[j][pilha[j].back().second] = i; pilha[j].pop_back(); zeros++; marc[j] = 1; } if(pilha[j].front().first == 1){ ans[j][pilha[j].front().second] = i; pilha[j].pop_front(); ones++; marc[j] = 1; } } for(int j = 0; j < n; j++){ if(marc[j]) continue; if(zeros < ones){ ans[j][pilha[j].back().second] = i; pilha[j].pop_back(); zeros++; marc[j] = 1; } else{ ans[j][pilha[j].front().second] = i; pilha[j].pop_front(); ones++; marc[j] = 1; } } } allocate_tickets(ans); return sum /= 2; } long long sum = 0; for(int c = 0; c < k; c++){ vector<long long> dp (n); vector<vector<bool> > bt (n, vector<bool> (n, 0)); for(int i = 0; i < n; i++){ for(int j = n / 2; j >= 0; j--){ dp[j] = dp[j] - pilha[i].front().first; if(j != 0 && dp[j - 1] + pilha[i].back().first > dp[j]) dp[j] = dp[j - 1] + pilha[i].back().first, bt[i][j] = 1; } } int curI = n - 1, curJ = n / 2; while(curI >= 0){ if(bt[curI][curJ]) curJ--, ans[curI][pilha[curI].back().second] = c, pilha[curI].pop_back(); else ans[curI][pilha[curI].front().second] = c, pilha[curI].pop_front(); curI--; } sum += dp[n / 2]; } allocate_tickets(ans); return sum; }

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

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:38:9: warning: unused variable 'aux' [-Wunused-variable]
   38 |     int aux = m - cnt;
      |         ^~~
#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...