# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
130070 | 2019-07-13T20:40:19 Z | TadijaSebez | Olympiads (BOI19_olympiads) | C++11 | 318 ms | 1948 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair const int N=505; const int K=6; int a[K][N],n,k,c; vector<int> vals[K]; int Val(vector<int> state) { int ans=0; for(int i=0;i<k;i++) ans+=vals[i][state[i]]; return ans; } void Answer(vector<int> state) { printf("%i\n",Val(state)); exit(0); } ll cnt[1<<K],dp[K+1][1<<K],use[K+1]; ll Get(vector<int> state) { for(int i=0;i<1<<k;i++) cnt[i]=0; for(int i=1;i<=n;i++) { bool ok=1; int mask=0; for(int j=0;j<k;j++) { if(a[j][i]>vals[j][state[j]]) ok=0; if(a[j][i]==vals[j][state[j]]) mask|=1<<j; } if(ok) cnt[mask]++; } for(int i=0;i<=k;i++) for(int j=0;j<1<<k;j++) dp[i][j]=0; dp[0][0]=1; for(int l=0;l<1<<k;l++) { for(int i=0;i<=k;i++) { use[i]=1; for(int j=0;j<i;j++) use[i]*=cnt[l]-j; for(int j=1;j<=i;j++) use[i]/=j; } for(int i=k;i>=0;i--) for(int j=0;j<1<<k;j++) { for(int r=1;r<=k-i;r++) { dp[i+r][j|l]+=dp[i][j]*use[r]; } } } return dp[k][(1<<k)-1]; } void Check(vector<int> state) { ll del=Get(state); if(del>=c) Answer(state); c-=del; } vector<int> Next(vector<int> state, int t) { state[t]++; if(state[t]<vals[t].size()) return state; else return vector<int>(0); } set<string> was; string ToString(vector<int> state) { string ans; for(int i=0;i<k;i++) ans+=(char)state[i]; return ans; } int main() { scanf("%i %i %i",&n,&k,&c); for(int i=1;i<=n;i++) for(int j=0;j<k;j++) scanf("%i",&a[j][i]),vals[j].push_back(a[j][i]); for(int i=0;i<k;i++) { sort(vals[i].rbegin(),vals[i].rend()); vals[i].resize(unique(vals[i].begin(),vals[i].end())-vals[i].begin()); } priority_queue<pair<int,vector<int>>> pq; vector<int> st; for(int j=0;j<k;j++) st.push_back(0); auto Push=[&](vector<int> state) { string s=ToString(state); if(!was.count(s)) { pq.push({Val(state),state}); was.insert(s); } }; Push(st); while(pq.size()) { vector<int> state=pq.top().second; pq.pop(); Check(state); for(int i=0;i<k;i++) { vector<int> nxt=Next(state,i); if(nxt.size()) Push(nxt); } } printf(":D\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 60 ms | 476 KB | Output is correct |
2 | Correct | 184 ms | 1044 KB | Output is correct |
3 | Correct | 206 ms | 1184 KB | Output is correct |
4 | Correct | 212 ms | 1148 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 8 ms | 376 KB | Output is correct |
4 | Correct | 8 ms | 376 KB | Output is correct |
5 | Correct | 8 ms | 408 KB | Output is correct |
6 | Correct | 30 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 380 KB | Output is correct |
5 | Correct | 60 ms | 476 KB | Output is correct |
6 | Correct | 184 ms | 1044 KB | Output is correct |
7 | Correct | 206 ms | 1184 KB | Output is correct |
8 | Correct | 212 ms | 1148 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 376 KB | Output is correct |
11 | Correct | 8 ms | 376 KB | Output is correct |
12 | Correct | 8 ms | 376 KB | Output is correct |
13 | Correct | 8 ms | 408 KB | Output is correct |
14 | Correct | 30 ms | 376 KB | Output is correct |
15 | Correct | 311 ms | 1056 KB | Output is correct |
16 | Correct | 84 ms | 888 KB | Output is correct |
17 | Incorrect | 318 ms | 1948 KB | Output isn't correct |
18 | Halted | 0 ms | 0 KB | - |