제출 #1332290

#제출 시각아이디문제언어결과실행 시간메모리
1332290MisterReaperNaan (JOI19_naan)C++20
100 / 100
280 ms110312 KiB
#include <bits/stdc++.h>

using i64 = long long;

#ifdef DEBUG
    #include "debug.h"
#else
    #define debug(...) void(23)
#endif

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int N, L;
    std::cin >> N >> L;

    std::vector<std::vector<int>> A(N, std::vector<int>(L));
    std::vector<std::vector<i64>> ps(N, std::vector<i64>(L + 1));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < L; ++j) {
            std::cin >> A[i][j];
            ps[i][j + 1] = ps[i][j] + A[i][j];
        }
    }

    std::vector<std::vector<std::pair<i64, int>>> rg(N, std::vector<std::pair<i64, int>>(N));
    for (int i = 0; i < N; ++i) {
        for (int j = 0, k = 0; j < N - 1; ++j) {
            while (ps[i][k + 1] * N <= ps[i][L] * (j + 1)) {
                ++k;
            }
            rg[i][j] = {ps[i][L] * (j + 1) - ps[i][k] * N + 1LL * k * N * A[i][k], A[i][k] * N};
            debug(i, j, rg[i][j]);
        }
        debug();
    }

    std::vector<int> vis(N);
    std::vector<int> pm(N);
    for (int i = 0; i < N - 1; ++i) {
        int x = -1;
        i64 p = L * N;
        int q = N;
        for (int j = 0; j < N; ++j) {
            if (vis[j]) {
                continue;
            }
            auto[a, b] = rg[j][i];
            if (a * (q / N) < p * (b / N)) {
                x = j;
                p = a;
                q = b;
            }
        }
        pm[i] = x;
        vis[x] = true;
    }

    for (int i = 0; i < N; ++i) {
        if (!vis[i]) {
            pm[N - 1] = i;
            break;
        }
    }

    for (int i = 0; i < N - 1; ++i) {
        auto[p, q] = rg[pm[i]][i];
        assert(1 <= q && q <= int(1E9));
        std::cout << p << ' ' << q << '\n';
    }
    for (int i = 0; i < N; ++i) {
        std::cout << pm[i] + 1 << " \n"[i == N - 1];
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...