# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
124891 |
2019-07-04T05:39:58 Z |
이온조(#3049) |
Olympiads (BOI19_olympiads) |
C++14 |
|
49 ms |
4080 KB |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using piv = pair<int, vector<int> >;
vector<pii> S[7];
int N, C, A[509][7];
set<vector<int> > st, vs;
bool operator <(piv PP, piv QQ) {
return PP.first < QQ.first;
}
vector<int> V;
void go(vector<bool> &chk, int lft, int idx) {
if(C <= 0) return;
if(idx == N+1) {
if(lft) return;
if(st.find(V) == st.end()) --C;
st.insert(V);
return;
}
if(chk[idx]) {
V.push_back(idx);
go(chk, lft, idx+1);
V.pop_back();
}
else {
if(lft) {
V.push_back(idx);
go(chk, lft - 1, idx + 1);
V.pop_back();
}
go(chk, lft, idx + 1);
}
}
int main() {
int K; scanf("%d%d%d",&N,&K,&C);
for(int i=1; i<=N; i++) {
for(int j=0; j<K; j++) {
scanf("%d",&A[i][j]);
S[j].push_back({A[i][j], i});
}
}
for(int i=0; i<K; i++) {
sort(S[i].begin(), S[i].end());
reverse(S[i].begin(), S[i].end());
}
int s = 0;
for(int i=0; i<K; i++) s += S[i][0].first;
priority_queue<pair<int, vector<int> > > pq;
pq.push({s, {0, 0, 0, 0, 0, 0}}); vs.insert(pq.top().second);
while(pq.size()) {
int sum, ns = 0; vector<int> T;
tie(sum, T) = pq.top(); pq.pop();
for(int i=0; i<K; i++) {
vector<int> X = T;
if(T[i] + 1 < N) {
++X[i];
if(vs.find(X) == vs.end()) {
pq.push({sum - S[i][T[i]].first + S[i][T[i] + 1].first, X});
vs.insert(X);
}
}
}
vector<bool> chk(N+1, 0); int Z = 0;
for(int i=0; i<K; i++) chk[S[i][T[i]].second] = 1;
for(int i=1; i<=N; i++) if(chk[i]) ++Z;
V = vector<int>();
go(chk, K-Z, 1);
if(C <= 0) return !printf("%d", sum);
}
return 0;
}
Compilation message
olympiads.cpp: In function 'int main()':
olympiads.cpp:56:12: warning: unused variable 'ns' [-Wunused-variable]
int sum, ns = 0; vector<int> T;
^~
olympiads.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int K; scanf("%d%d%d",&N,&K,&C);
~~~~~^~~~~~~~~~~~~~~~~~~
olympiads.cpp:43:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&A[i][j]);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
632 KB |
Output is correct |
2 |
Correct |
12 ms |
760 KB |
Output is correct |
3 |
Correct |
10 ms |
636 KB |
Output is correct |
4 |
Correct |
17 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
17 ms |
1400 KB |
Output is correct |
3 |
Correct |
12 ms |
1416 KB |
Output is correct |
4 |
Correct |
13 ms |
1532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
760 KB |
Output is correct |
2 |
Correct |
7 ms |
504 KB |
Output is correct |
3 |
Correct |
20 ms |
1908 KB |
Output is correct |
4 |
Correct |
22 ms |
2292 KB |
Output is correct |
5 |
Correct |
23 ms |
1492 KB |
Output is correct |
6 |
Correct |
49 ms |
4080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
632 KB |
Output is correct |
2 |
Correct |
12 ms |
760 KB |
Output is correct |
3 |
Correct |
10 ms |
636 KB |
Output is correct |
4 |
Correct |
17 ms |
760 KB |
Output is correct |
5 |
Correct |
5 ms |
632 KB |
Output is correct |
6 |
Correct |
17 ms |
1400 KB |
Output is correct |
7 |
Correct |
12 ms |
1416 KB |
Output is correct |
8 |
Correct |
13 ms |
1532 KB |
Output is correct |
9 |
Correct |
9 ms |
760 KB |
Output is correct |
10 |
Correct |
7 ms |
504 KB |
Output is correct |
11 |
Correct |
20 ms |
1908 KB |
Output is correct |
12 |
Correct |
22 ms |
2292 KB |
Output is correct |
13 |
Correct |
23 ms |
1492 KB |
Output is correct |
14 |
Correct |
49 ms |
4080 KB |
Output is correct |
15 |
Correct |
21 ms |
1400 KB |
Output is correct |
16 |
Correct |
12 ms |
1016 KB |
Output is correct |
17 |
Correct |
23 ms |
2416 KB |
Output is correct |
18 |
Correct |
22 ms |
2036 KB |
Output is correct |
19 |
Correct |
7 ms |
632 KB |
Output is correct |