답안 #850776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850776 2023-09-17T12:26:39 Z serifefedartar Olympiads (BOI19_olympiads) C++17
0 / 100
135 ms 20448 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 20;
const ll MAXN = 505;

vector<vector<int>> p;
int N, K, C;
struct Rule {
    vector<int> r;
    int res;
    Rule(vector<int> rl) {
        r = rl;
        res = 0;
    }

    int calc() {
        int cnt = 0;

        for (int i = 0; i < r.size(); i++) {
            if (r[i] == 2)
                r[i] = 0;
        }

        set<int> taken;
        for (int i = 0; i < N; i++) {
            if (r[i] == 1) {
                cnt++;
                taken.insert(i);
            }
        }

        for (int i = cnt; i < K; i++) {
            int mx = 0;
            int mx_ind = -1;
            for (int j = 0; j < N; j++) {
                if (r[j] != -1 && taken.count(j) == 0 && mx <= p[j][i]) {
                    mx = p[j][i];
                    mx_ind = j;
                }
            }
            if (mx_ind != -1)
                taken.insert(mx_ind);
        }

        if (taken.size() != K)
            res = -1;
        else {
            for (auto u : taken)
                r[u] = 2;

            for (int i = 0; i < K; i++) {
                int mx_here = 0;
                for (auto u : taken)
                    mx_here = max(mx_here, p[u][i]);
                res += mx_here;
            }
        }

        return res;
    }
};

bool operator <(Rule A, Rule B) {
        return A.res < B.res;
}

int main() {
    fast
    cin >> N >> K >> C;

    p = vector<vector<int>>(N, vector<int>(K));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < K; j++)
            cin >> p[i][j];
    }

    priority_queue<Rule> pq;
    vector<int> emp(N, 0);
    Rule new_rule = Rule(emp);
    new_rule.calc();
    pq.push(new_rule);

    while (true) {
        Rule now = pq.top();
        pq.pop();
        C--;

        if (C == 0) {
            cout << now.res << "\n";
            exit(0);
        }

        vector<int> R = now.r;
        for (int i = 0; i < N; i++) {
            if (R[i] == 2) {
                R[i] = -1;
                new_rule = Rule(R);
                new_rule.calc();

                pq.push(new_rule);
                R[i] = 1;              
            }
        }
    }
}

Compilation message

olympiads.cpp: In member function 'int Rule::calc()':
olympiads.cpp:25:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (int i = 0; i < r.size(); i++) {
      |                         ~~^~~~~~~~~~
olympiads.cpp:51:26: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |         if (taken.size() != K)
      |             ~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 4432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 20424 KB Output is correct
2 Correct 91 ms 20424 KB Output is correct
3 Incorrect 135 ms 20448 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 4432 KB Output isn't correct
2 Halted 0 ms 0 KB -