답안 #984328

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
984328 2024-05-16T13:33:44 Z kh0i Olympiads (BOI19_olympiads) C++17
13 / 100
26 ms 792 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif

using ll = long long;
using pii = pair<int, int>;

#define F first
#define S second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll get_rand(ll l, ll r) {
    assert(l <= r);
    return uniform_int_distribution<ll> (l, r)(rng);
}

#define BB bitset<3000>

int n, k, c;

struct Point{
    int i, j, pt;
    friend bool operator < (const Point &x, const Point &y){ return x.pt > y.pt; }
};

vector<Point> e;

struct Partition{
    BB banned;
    int fix = 0;
    ll weight = 0;
    vector<int> span;

    Partition(BB _banned, int _fix) : banned(_banned), fix(_fix) {
        vector<bool> used(k, 0);
        vector<bool> in_span(n, 0);
        for(int i = 0; i < sz(e); ++i){
            if(!banned[i] and !used[e[i].j]){
                weight += e[i].pt;
                used[e[i].j] = 1;
                if(!in_span[e[i].i])
                    span.push_back(i);
                in_span[e[i].i] = 1;
            }
        }
        for(int i = 0; i < sz(e); ++i){
            if(sz(span) == k)
                break;
            if(banned[i] or in_span[e[i].i])
                continue;
            span.push_back(i);
            in_span[e[i].i] = 1;
        }
        sort(all(span));
    }

    bool friend operator < (const Partition &x, const Partition &y){ return x.weight < y.weight; }
};

void solve(){
    cin >> n >> k >> c;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < k; ++j){
            int x;
            cin >> x;
            e.push_back({i, j, x});
        }
    }

    sort(all(e));
    priority_queue<Partition> pq;
    pq.push(Partition(BB(), 0));

    for(int iter = 1; iter <= c; ++iter){
        assert(!pq.empty());
        Partition a = pq.top();
        pq.pop();

        debug(a.weight, a.span, a.fix);
        for(int i : a.span)
            debug(e[i].i, e[i].j, e[i].pt);

        if(iter == c){
            cout << a.weight;
            return;
        }

        while(a.fix < sz(a.span)){
            BB t = a.banned;
            t[a.span[a.fix]] = 1;
            for(int i = 0; i < sz(e); ++i)
                if(e[i].i == e[a.span[a.fix]].i)
                    t[i] = 1;
            auto A = Partition(t, a.fix);
            if(sz(A.span) == k)
                pq.push(A);
            ++a.fix;
        }
    }
}

int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(0);
    #define task "troll"
    if(fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int test = 1;
//    cin >> test;
    for(int i = 1; i <= test; ++i){
//        cout << "Case #" << i << ": ";
        solve();
    }
    #ifdef LOCAL
        cerr << "\n[Time]: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    #endif
    return 0;
}

Compilation message

olympiads.cpp: In function 'void solve()':
olympiads.cpp:87:17: warning: unused variable 'i' [-Wunused-variable]
   87 |         for(int i : a.span)
      |                 ^
olympiads.cpp: In function 'int32_t main()':
olympiads.cpp:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
olympiads.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 9 ms 528 KB Output is correct
3 Correct 8 ms 348 KB Output is correct
4 Correct 7 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 572 KB Output is correct
2 Correct 17 ms 348 KB Output is correct
3 Correct 21 ms 700 KB Output is correct
4 Correct 26 ms 576 KB Output is correct
5 Incorrect 20 ms 604 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 9 ms 528 KB Output is correct
3 Correct 8 ms 348 KB Output is correct
4 Correct 7 ms 492 KB Output is correct
5 Incorrect 5 ms 792 KB Output isn't correct
6 Halted 0 ms 0 KB -