# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730054 | lovrot | Olympiads (BOI19_olympiads) | C++17 | 76 ms | 4648 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int, int> pii;
const int N = 500;
const int K = 6;
int n, k, event[N][K];
//perm; -1 => ban | 0 => whatever | 1 => must
struct space {
char perm[N], cnt;
int best[K], score;
space() {
for(int i = 0; i < N; i++) perm[i] = 0;
for(int i = 0; i < K; i++) best[i] = -1;
cnt = score = 0;
}
void evaluate() {
for(int i = 0; i < n; i++)
if(perm[i] == 1) {
best[cnt] = i;
cnt++;
}
for(int i = cnt; i < k; i++) {
best[i] = -1;
for(int j = 0; j < n; j++) {
bool flag = true;
for(int l = 0; l < i; l++) flag &= j != best[l];
if(flag && perm[j] == 0 && (best[i] == -1 || event[best[i]][i] < event[j][i]))
best[i] = j;
}
}
for(int i = 0; i < k; i++) {
//printf("/ best %d\n", best[i]);
int xam = 0;
for(int j = 0; j < k; j++) xam = max(xam, event[best[j]][i]);
score += xam;
}
//printf("/ score %d\n", score);
}
bool operator< (space s) const {
return score < s.score;
}
};
priority_queue<space> q;
void debug(const space &s) {
for(int i = 0; i < n; i++) printf("%d ", s.perm[i]);
printf("\n");
for(int i = 0; i < k; i++) printf("%d ", s.best[i]);
printf("\n%d %d\n", s.score, s.cnt);
}
void fracture(space &s) {
for(int i = 0; i < s.cnt; i++) s.perm[s.best[i]] = 1;
for(int i = s.cnt; i < k; i++) {
s.perm[s.best[i]] = -1;
space _s = space();
for(int j = 0; j < n; j++) _s.perm[j] = s.perm[j];
_s.evaluate();
if(_s.best[k - 1] != -1) {
q.push(_s);
//debug(_s);
}
s.perm[s.best[i]] = 1;
}
}
int t;
int main() {
scanf("%d%d%d", &n, &k, &t);
for(int i = 0; i < n; i++)
for(int j = 0; j < k; j++)
scanf("%d", &event[i][j]);
space s = space();
s.evaluate();
q.push(s);
int cnt = 0;
while(1) {
cnt++;
space _s = q.top();
q.pop();
//debug(s);
if(cnt == t) {
printf("%d\n", _s.score);
break;
}
fracture(_s);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |