제출 #769135

#제출 시각아이디문제언어결과실행 시간메모리
769135t6twotwo카니발 티켓 (IOI20_tickets)C++17
41 / 100
583 ms72904 KiB
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll find_maximum(int K, vector<vector<int>> x) {
    int N = x.size();
    int M = x[0].size();
    if (M == 1) {
        allocate_tickets(vector(N, vector{0}));
        vector<int> v(N);
        for (int i = 0; i < N; i++) {
            v[i] = x[i][0];
        }
        sort(v.begin(), v.end());
        ll s = 0;
        for (int i = 0; i < N; i++) {
            s += abs(v[N / 2] - v[i]);
        }
        return s;
    }
    if (K == 1) {
        vector dp(N + 1, vector<ll>(N / 2 + 1, -1e18));
        dp[0][0] = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= N / 2; j++) {
                if (j < N / 2) {
                    dp[i + 1][j + 1] = dp[i][j] + x[i][M - 1];
                }
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] - x[i][0]);
            }
        }
        vector a(N, vector<int>(M, -1));
        for (int i = N - 1, j = N / 2; i >= 0; i--) {
            if (dp[i][j] - x[i][0] == dp[i + 1][j]) {
                a[i][0] = 0;
            } else {
                a[i][M - 1] = 0;
                j--;
            }
        }
        allocate_tickets(a);
        return dp[N][N / 2];
    }
    if (K == M) {
        vector<tuple<int, int, int>> v;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                v.emplace_back(x[i][j], i, j);
            }
        }
        sort(v.begin(), v.end());
        vector f(N, vector<bool>(M));
        ll ans = 0;
        for (int i = 0; i < N * M / 2; i++) {
            auto [t, x, y] = v[i];
            ans -= t;
        }
        for (int i = N * M / 2; i < N * M; i++) {
            auto [t, x, y] = v[i];
            ans += t;
            f[x][y] = 1;
        }
        vector a(N, vector<int>(M));
        int x = 0, y = K - 1;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                if (!f[i][j]) {
                    a[i][j] = y--;
                } else {
                    a[i][j] = x++;
                }
                if (y == -1) {
                    y = K - 1;
                }
                if (x == K) {
                    x = 0;
                }
            }
        }
        allocate_tickets(a);
        return ans;
    }
}

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

tickets.cpp: In function 'll find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:83:1: warning: control reaches end of non-void function [-Wreturn-type]
   83 | }
      | ^
#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...