답안 #444150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444150 2021-07-13T07:21:02 Z JovanB Olympiads (BOI19_olympiads) C++17
100 / 100
6 ms 2008 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;

int n, k;

int mat[505][10];
vector <pair <int, int>> best[10];

struct SearchSpace{
    int score = 0;
    vector <int> tak;
    bitset <505> zab;
    bitset <505> used;
    int fix = 0;
    int sum[7];
    void eval(const int _fix, const vector <int> &_tak, const bitset <505> &_zab){
        tak = _tak;
        zab = _zab;
        used.reset();
        for(auto c : tak) used[c] = 1;
        fix = _fix;
        for(int i=1; i<=k; i++) sum[i] = 0;
        for(int i=fix+1; i<=k; i++){
            bool found = 0;
            for(auto c : best[i]){
                int tk = c.second;
                if(used[tk] || zab[tk]) continue;
                found = 1;
                used[tk] = 1;
                tak.push_back(tk);
                break;
            }
            if(!found){
                score = -1;
                return;
            }
        }
        for(auto c : tak){
            for(int j=1; j<=k; j++){
                sum[j] = max(sum[j], mat[c][j]);
            }
        }
        score = 0;
        for(int j=1; j<=k; j++) score += sum[j];
    }
    bool operator <(const SearchSpace &s) const { return score < s.score; }
};

bitset <505> def;
vector <int> empt;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int m;
    cin >> n >> k >> m;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=k; j++){
            cin >> mat[i][j];
            best[j].push_back({mat[i][j], i});
        }
    }
    for(int i=1; i<=k; i++){
        sort(best[i].begin(), best[i].end());
        reverse(best[i].begin(), best[i].end());
    }
    priority_queue <SearchSpace> pq;
    SearchSpace prvi;
    prvi.eval(0, empt, def);
    pq.push(prvi);
    while(m){
        SearchSpace sp = pq.top();
        pq.pop();
        m--;
        if(m == 0){
            cout << sp.score << "\n";
            return 0;
        }
        vector <int> tkk;
        bitset <505> zab = sp.zab;
        for(int i=0; i<sp.fix; i++) tkk.push_back(sp.tak[i]);
        for(int fix=sp.fix; fix<k; fix++){
            SearchSpace novi;
            zab[sp.tak[fix]] = 1;
            novi.eval(fix, tkk, zab);
            zab[sp.tak[fix]] = 0;
            pq.push(novi);
            tkk.push_back(sp.tak[fix]);
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 796 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 4 ms 1240 KB Output is correct
4 Correct 4 ms 796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 1244 KB Output is correct
4 Correct 4 ms 1244 KB Output is correct
5 Correct 5 ms 1244 KB Output is correct
6 Correct 3 ms 796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 3 ms 796 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 4 ms 1240 KB Output is correct
8 Correct 4 ms 796 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 4 ms 1244 KB Output is correct
12 Correct 4 ms 1244 KB Output is correct
13 Correct 5 ms 1244 KB Output is correct
14 Correct 3 ms 796 KB Output is correct
15 Correct 3 ms 588 KB Output is correct
16 Correct 4 ms 1244 KB Output is correct
17 Correct 6 ms 2008 KB Output is correct
18 Correct 4 ms 860 KB Output is correct
19 Correct 3 ms 332 KB Output is correct