제출 #300924

#제출 시각아이디문제언어결과실행 시간메모리
300924IgorI카니발 티켓 (IOI20_tickets)C++17
27 / 100
778 ms51448 KiB
#include "tickets.h"
#include <bits/stdc++.h>

using namespace std;

long long find_maximum(int k, std::vector<std::vector<int>> x)
{
    int mx = 0;
    int n = x.size(), m = x[0].size();
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            mx = max(mx, x[i][j]);
        }
    }
    if (mx == 1)
    {
        long long res;
        vector<vector<int> > ans(n, vector<int>(m, -1));
        vector<pair<int, int> > z;
        vector<int> fr(n), to(n, m - 1);
        for (int i = 0; i < n; i++)
        {
            int cnt = 0;
            for (int j = 0; j < m; j++)
            {
                cnt += (x[i][j] == 0);
            }
            z.push_back({cnt, i});
        }
        for (int j = 0; j < k; j++)
        {
            sort(z.begin(), z.end());
            reverse(z.begin(), z.end());
            int cnt0 = 0, cnt1 = 0;
            for (int i = 0; i < n / 2; i++)
            {
                if (z[i].first > 0)
                {
                    z[i].first--;
                    ans[z[i].second][fr[z[i].second]] = j;
                    fr[z[i].second]++;
                    cnt0++;
                }
                else
                {
                    ans[z[i].second][to[z[i].second]] = j;
                    to[z[i].second]--;
                    cnt1++;
                }
            }
            for (int i = n / 2; i < n; i++)
            {
                if (z[i].first < m - j)
                {
                    ans[z[i].second][to[z[i].second]] = j;
                    to[z[i].second]--;
                    cnt1++;
                }
                else
                {
                    z[i].first--;
                    ans[z[i].second][fr[z[i].second]] = j;
                    fr[z[i].second]++;
                    cnt0++;
                }
            }
            res += min(cnt0, cnt1);
        }
        allocate_tickets(ans);
        return res;
    }
    vector<pair<long long, int> > improve;
    vector<vector<int> > ans(n, vector<int>(m, -1));
    long long si = 0;
    for (int i = 0; i < n; i++)
    {
        si -= x[i][0];
        improve.push_back({x[i][0] + x[i][m - 1], i});
    }
    sort(improve.begin(), improve.end());
    reverse(improve.begin(), improve.end());
    for (int i = 0; i < n / 2; i++)
    {
        ans[improve[i].second][m - 1] = 0;
        si += improve[i].first;
    }
    for (int i = n / 2; i < n; i++)
    {
        ans[improve[i].second][0] = 0;
    }
    allocate_tickets(ans);
    return si;
}

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

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:19:19: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   19 |         long long res;
      |                   ^~~
#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...