結果

問題 No.3049 Contest Coordinator
ユーザー zawakasu
提出日時 2025-03-07 22:52:08
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 3,044 bytes
コンパイル時間 1,856 ms
コンパイル使用メモリ 141,168 KB
実行使用メモリ 15,284 KB
最終ジャッジ日時 2025-03-07 22:52:19
合計ジャッジ時間 10,128 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 58
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
int N, T, X, Y, D[500050];
std::vector<long long> naive() {
    std::vector<long long> res(N, (long long)9e18);
    std::vector<int> cur;
    auto f = [&]() -> void {
        if (cur.empty()) return;
        std::vector<int> a(cur.size());
        for (int i = 0 ; i < (int)a.size() ; i++) a[i] = D[cur[i]];
        std::sort(a.begin(), a.end()); 
        do {
            long long sc = 0LL;
            for (int i = 0 ; i + 1 < (int)a.size() ; i++) {
                if (a[i + 1] - a[i] > T) sc += X;
                else if (a[i + 1] - a[i] < 0LL) sc += Y;
            }
            res[a.size() - 1] = std::min(res[a.size() - 1], sc);
        } while (std::next_permutation(a.begin(), a.end()));
    };
    auto dfs = [&](auto dfs, int i) -> void {
        if (i == N) {
            f();
            return;
        }
        cur.push_back(i);
        dfs(dfs, i + 1);
        cur.pop_back();
        dfs(dfs, i + 1);
    };
    dfs(dfs, 0);
    return res;
}
std::vector<long long> solve() {
    std::sort(D, D + N);
    std::vector<int> A(N - 1);
    for (int i = 0 ; i + 1 < N ; i++) A[i] = (D[i + 1] - D[i] > T ? 1 : 0);
    A.push_back(1);
    std::vector<int> L;
    for (int i = 0 ; i < N ; i++) if (A[i] == 1) {
        int j = i - 1;
        while (j >= 0 and A[j] == 0) j--;
        L.push_back(i - j);
    }
    std::sort(L.begin(), L.end(), std::greater<int>{});
    std::vector<long long> ans(N);
    int p = 0, s = 0, c = 0;
    for (auto l : L) {
        s += l;
        for (int i = p ; i < s ; i++) ans[i] = (long long)c * std::min(X, Y);
        c++;
        p = s;
    }
    return ans;
}
#include <random>
std::mt19937 mt{std::random_device{}()};
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cin >> N >> T >> X >> Y;
    for (int i = 0 ; i < N ; i++) std::cin >> D[i];
    auto ans = solve();
    for (int i = 0 ; i < N ; i++) std::cout << ans[i] << (i + 1 == N ? '\n' : ' ');
//     while (true) {
//     N = mt() % 8 + 1;
//     T = mt() % 3 + 1;
//     X = mt() % 20 + 1;
//     Y = mt() % 20 + 1;
//     for (int i = 0 ; i < N ; i++) {
//         D[i] = mt() % 100 + 1;
//     }
//     std::cout << "------------------------" << std::endl;
//     std::cout << N << ' ' << T << ' ' << X << ' ' << Y << '\n';
//     for (int i = 0 ; i < N ; i++) std::cout << D[i] << (i + 1 == N ? '\n' : ' ');
//     auto ans = naive(), my = solve();
//     if (ans != my) {
//         for (auto m : my) std::cout << m << ' ';
//         std::cout << std::endl;
//         for (auto m : ans) std::cout << m << ' ';
//         std::cout << std::endl;
//         std::exit(0);
//     }
// }
}
0